Fix: Disconnect before reconnecting to prevent duplication #90
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Automattic/simplenote-electron we noticed that after signing out of
the application and signing in again we were getting infinite
duplication of changes. This occurred until we quit the app and
restarted it.
We discovered that when signing back in the Simperium client library was
opening a new WebSocket connection without closing the old one. Whenever
the server sent back changes the client got them twice and tried to
update the content twice, which then cascaded duplication without end.
In this patch we're closing the existing connection if it's already open
when we call
connect()
. This probably fixes defects we haven'tassociated with this change.
Testing
npm run prepare && npm link
npm link simperium && npm run dev
With this branch
npm link
ed when you logout/login and type something in a note the app should enter your changes and things will work as expected.Without this branch when you logout/login and type something then you should see after a short delay that you change replays infinitely and duplicates itself.