Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

OfflineStore removeEntry expects v1:queue:yyyy but it's called with queue:yyyy #909

Closed
AnderLuiz opened this issue Oct 19, 2020 · 3 comments

Comments

@AnderLuiz
Copy link

AnderLuiz commented Oct 19, 2020

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

  1. Add an operation that server will reject (fail).
  2. Add an operation that will not fail.
  3. 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);
  }
@AnderLuiz AnderLuiz changed the title OfflineStore removeEntry expects v1:queue:yyyy but is called with queue:yyyy OfflineStore removeEntry expects v1:queue:yyyy but it's called with queue:yyyy Oct 19, 2020
@bureyburey
Copy link

bureyburey commented Dec 6, 2020

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.

@wtrocki
Copy link
Contributor

wtrocki commented Dec 7, 2020

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

@kingsleyzissou
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants