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

Data synchronization race conditions? #74

Closed
maxfi opened this issue Dec 4, 2013 · 1 comment
Closed

Data synchronization race conditions? #74

maxfi opened this issue Dec 4, 2013 · 1 comment

Comments

@maxfi
Copy link

maxfi commented Dec 4, 2013

I haven't yet had a chance to closely inspect the code or do my own testing but was wondering what happens if the client is offline and makes some changes to a model whilst at the same time changes are made to the same model on the server?

  1. When the client comes back online (tested by doing a http ping to the server) and syncDirtyAndDestroyed() is called by an onlineStatusChecker function does the client or the server "win"?
  2. What happens if fetch is called on the model's collection before syncDirtyAndDestroyed() is called?
  3. What happens if syncDirtyAndDestroyed() is called before fetch but the ajax requests haven't yet completed?
@nilbus
Copy link
Owner

nilbus commented Dec 20, 2013

  1. The client probably wins, but you could teach the server to recognize outdated updates, perhaps by checking a timestamp, according to your app's business rules. In more concrete terms, when syncDirtyAndDestroyed syncs successfully, it will send create/update/destroy requests to the server as if they had just been performed.
  2. fetch, AKA 'read', will load data from localStorage exclusively while there are any dirty or destroyed records. See https://github.com/nilbus/Backbone.dualStorage/blob/master/backbone.dualstorage.coffee#L249.
  3. For fetches, it looks like the entire local store for the collection/model gets cleared out after every successful fetch, which includes dirty and destroyed records. Before the syncDirtyAndDestroyed callback returns (while the ajax requests wait), any fetch on dirty records will return the data in localStorage.

On the topic of synchronicity issues, please be aware of #76 and #35, which has a workaround committed to master (cd17ff2).

The behavior of clearing the store when fetching a model seems like a bug to me. Opened #78 to address this.

@nilbus nilbus closed this as completed Dec 20, 2013
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

2 participants