There is a known (unresolved) issue with PouchDB which prohibits synchronization when the same database is instantiated in multiple tabs in the same browser. In my testing (6.4.1 with sync gateway on Chrome), the depth of this problem is much more severe than the error which is thrown when a new tab tries to instantiate a new sync process.
As far as I can tell, whenever a new tab tries to instantiate a new instance of the same sync process PouchDB.sync ALSO disables the sync process occurring in the original tab.
I'm not sure how it does this, since the other process is operating in a separate window, but I have noticed that the original tab no longer pushes nor pulls changes. What more, the original tab has no way of knowing that it has been disabled (since it emits no errors, changes or states to indicate this situation). And, there seems to be no way in PouchDB to check to see if another window already has a sync process is motion prior to attempting to start one (and encountering the error).
As a result, any web apps which rely upon { live: true, retry: true }
to automatically propagate client changes are likely to lose data if/when users open up a second tab. The data will only sync again with the server, once:
- all open tabs are closed
- a new tab is opened
- a signout/destroy event does not occur before 1 and 2.
This also immediately disables any changes the server wishes to send to the client.
Has anyone found a workaround?
Either by checking to see if sync is already running, or restart it when it is disabled? Or some other method? Otherwise, it seems that live syncing cannot be used in a production environment where a user may have more than one tab open at a time. The only way to avoid this problem seems to be to perform replication on demand.
SOLVED: The problem appears to come from the Origin Request Limits of the browser rather than PouchDB. Having too many sync processes running simultaneously to the same address causes the browser to disable them in a way which does not report an error. Thanks to Dale Harvey for helping identify the culprit.