OfflineStore removeEntry expects v1:queue:yyyy but it's called with queue:yyyy
AnderLuiz opened this issue · comments
Bug Report
The following function is the removeEntry
function. It will only remove the entry if arrayOfKeys
has entry.qid
.
public async removeEntry(entry: QueueEntryOperation<T>) {
this.arrayOfKeys.splice(this.arrayOfKeys.indexOf(entry.qid), 1);
this.storage.setItem(this.offlineMetaKey, this.arrayOfKeys);
const offlineKey = this.getOfflineKey(entry.qid);
await this.storage.removeItem(offlineKey);
}
https://github.com/aerogear/offix/blob/master/packages/offix/scheduler/src/store/OfflineStore.ts#L53
If entry.qid
is not found, then it will remove the last one from arrayOfKeys
, but will remove from storage the correct key.
Some logs:
Remove entry qid: queue:ja3mt2qcv
this.arrayOfKeys before splice: ["v1:queue:lnx9w178h", "v1:queue:zyx0kk1ov", "v1:queue:ja3mt2qcv", "v1:queue:cz64yxz1k"]
this.arrayOfKeys after splice: after ["v1:queue:lnx9w178h", "v1:queue:zyx0kk1ov", "v1:queue:ja3mt2qcv"]
RemovedItemFromStorage: v1:queue:ja3mt2qcv
- Affected Package(s): offix-scheduler
- Package version(s): 0.16.0-beta1
- Platform (e.g. Android/iOS): React-Native, Android and IOS
- Platform Version: 0.63
steps to reproduce
- Add an operation that server will reject (fail).
- Add an operation that will not fail.
- Add another operation that server will reject (fail).
When the app goes online, the removeEntry
will be called with entry.qid
===queue:XXXXX
, but it will only work if entry.qid
===v1:queue:XXXXX
EDIT:
This works:
public async removeEntry(entry: QueueEntryOperation<T>) {
const offlineKey = this.getOfflineKey(entry.qid);
this.arrayOfKeys.splice(this.arrayOfKeys.indexOf(offlineKey), 1);
this.storage.setItem(this.offlineMetaKey, this.arrayOfKeys);
await this.storage.removeItem(offlineKey);
}
Also experiencing this issue (version 0.15.5) and I would like to add that this has severe consequences since each success in the current session will remove an unproccesed entry.
If you were to restart the app after at least one entry success/failure (anything that calls the removeEntry method) and before ALL entries have been processed, the restoration of the entries will fail.
Furthermore, any future enqueues will be added but since the restoration (requeue) will fail due to an undefined entry value, this breaks the entire queue restoration mechanism.
Thank you for logging the issue.
I think this happened recently when we added v1 logic and it requires some chain of operations.
@AnderLuiz I think your proposed fix would work. If you are happy to create PR - myself and @kingsleyzissou can help to merge this
Hi @AnderLuiz, we have made the decision to move away from the Apollo client and we have decided to deprecate our Offix packages and release our Datastore. I will be closing this issue, but if you have any questions, please feel free to let us know.
You can see the docs for the updated datastore here:
https://offix.dev/docs/getting-started