Retrying a failed replication after initial connection failure?

44 views
Skip to first unread message

Johan Bäversjö

unread,
Jul 14, 2015, 3:24:49 PM7/14/15
to pou...@googlegroups.com
Hi

The PouchDB api has a {retry: true} setting for its db.sync() method. This works well when the replicator loses its connection in the middle of a session, however if no connection can be established initially when db.sync() is called, the replicator won't try to connect when the server is available again. I'm trying to handle the case where the web page is loaded offline, but goes online later, and should start syncing.

I worked around this by manually retrying the db.sync() if the replication was never started. This works except I get a memory warning from Pouch saying I've attached too many event handlers after ~10 retries. I tried resolving this by calling .cancel() on the object returned by db.sync() before retrying, however the .cancel() method is not available if the initial connection fails.

Any ideas on how to properly retry initial replication connections, or how to clean up the callbacks attached by (presumably) the db object by pouch?
Also, what's the best way for telling when a replication is active? It seems that, if there's no data to replicate. I have a solution that works in practice; if either "active" or "paused" is thrown, the replicator was connected. This is for an android wrapper app so webkit only solutions are fine.

Thanks for a great product!

Johan Baversjo

Dale Harvey

unread,
Jul 14, 2015, 4:21:06 PM7/14/15
to pou...@googlegroups.com
Its a bug that retry doesnt work if the connection isnt active when you start, its one that I thought someone reported and we have fixed, but not seeing it in the logs now, are you trying the latest version?

Either way have filed here https://github.com/pouchdb/pouchdb/issues/4049

As for checking for activity, you are right, `active` should fire while data is replicating, `paused` will fire when it is not (ie waiting for updates or a connection

Cheers
Dale



--
You received this message because you are subscribed to the Google Groups "PouchDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pouchdb+u...@googlegroups.com.
To post to this group, send email to pou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pouchdb/02e8bd89-7553-4247-9949-554aec1871a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johan Bäversjö

unread,
Jul 14, 2015, 4:37:46 PM7/14/15
to pou...@googlegroups.com
Hi Dale,

Thanks for filing that issue! Makes sense, I'll remove my internal retry logic then.

I'm using 3.6.0.

Cheers
Johan
Reply all
Reply to author
Forward
0 new messages