Skip to content

Commit

Permalink
fix: silently ignore session with unacknowledged write
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Reggi authored Jul 30, 2020
1 parent 72a743d commit 8f1ea7b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/core/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,11 @@ function applySession(session, command, options) {
return new MongoError('Cannot use a session that has ended');
}

// SPEC-1019: silently ignore explicit session with unacknowledged write for backwards compatibility
if (options && options.writeConcern && options.writeConcern.w === 0) {
return;
}

const serverSession = session.serverSession;
serverSession.lastUse = now();
command.lsid = serverSession.id;
Expand Down
23 changes: 23 additions & 0 deletions test/functional/sessions.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';

const withMonitoredClient = require('./shared').withMonitoredClient;
const expect = require('chai').expect;
const setupDatabase = require('./shared').setupDatabase;
const TestRunnerContext = require('./spec-runner').TestRunnerContext;
Expand Down Expand Up @@ -207,4 +209,25 @@ describe('Sessions', function() {

generateTopologyTests(testSuites, testContext, testFilter);
});
context('unacknowledged writes', () => {
it('should not include session for unacknowledged writes', {
metadata: { requires: { topology: 'single' } },
test: withMonitoredClient('insert', { clientOptions: { w: 0 } }, function(
client,
events,
done
) {
client
.db('test')
.collection('foo')
.insertOne({ foo: 'bar' }, err => {
expect(err).to.not.exist;
const event = events[0];
expect(event.command.writeConcern.w).to.equal(0);
expect(event.command.lsid).to.equal(undefined);
done();
});
})
});
});
});

0 comments on commit 8f1ea7b

Please sign in to comment.