Skip to content

Commit e3822e2

Browse files
authored
Fix: Disconnect before reconnecting to prevent duplication (#90)
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't associated with this change.
1 parent d069594 commit e3822e2

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

RELEASE-NOTES.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## Future Release
3+
## 1.0.1
4+
5+
- Disconnect from existing socket connection when connecting [#90](https://github.com/Simperium/node-simperium/pull/90)
6+
7+
## 1.0.0
48

59
### Fixes
610

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simperium",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "A simperium client for node.js",
55
"main": "./lib/simperium/index.js",
66
"repository": {

src/simperium/client.js

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ Client.prototype.sendChannelMessage = function( id, message ) {
179179
};
180180

181181
Client.prototype.connect = function() {
182+
if ( this.open ) {
183+
this.disconnect();
184+
}
185+
182186
this.reconnect = true;
183187
this.socket = this.options.websocketClientProvider( this.options.url );
184188

0 commit comments

Comments
 (0)