Skip to content

Commit d67f3b2

Browse files
committed
Discovered an issue where the local Simperium client was re-sending changes that had already been accepted by the server. This was caused by not recognizing the duplicate-change error and also by not acknowledging that a queued change had come back from the server in a change list. In this patch we're adding the duplicate-change handler to remove a change from the app's queue when the server tells us that it has already been applied. After this change we should see a reduction in duplicate-change load.
1 parent 671b3df commit d67f3b2

File tree

3 files changed

+71
-19
lines changed

3 files changed

+71
-19
lines changed

package-lock.json

Lines changed: 51 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/simperium/channel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ internal.handleChangeError = function( err, change, acknowledged ) {
240240

241241
break;
242242
case CODE_DUPLICATE_CHANGE:
243+
// no need to do anything else here - we already got this
243244
internal.updateAcknowledged.call( this, acknowledged );
244245
break;
245246
case CODE_EMPTY_RESPONSE: // Change causes no change, just acknowledge it

test/simperium/channel_test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,25 @@ describe( 'Channel', function() {
416416
channel.handleMessage( 'c:' + JSON.stringify( [{error: 405, id: 'thing', ccids: ['abc']}] ) );
417417
} );
418418

419+
it( 'should stop sending duplicate changes after receiving a 409', done => {
420+
const change = {o: 'M', id: 'thing', sv: 1, ccid: 'duplicate', v: diff( {}, {key: 'value'} )};
421+
422+
channel.localQueue.queue( change );
423+
424+
channel.once( 'send', () => {
425+
// we should sent out our change the first time
426+
channel.on( 'error', done );
427+
channel.localQueue.once( 'queued', () => done( 'Should not queue duplicate changes' ) );
428+
channel.once( 'acknowledge', () => done() );
429+
430+
channel.handleMessage( 'c:' + JSON.stringify( [{
431+
id: 'thing',
432+
error: 409,
433+
ccids: ['duplicate']
434+
}] ) );
435+
} );
436+
} );
437+
419438
describe( 'with synced object', () => {
420439
beforeEach( ( done ) => {
421440
var data = { title: 'hola mundo' };

0 commit comments

Comments
 (0)