Skip to content

Commit a053f4e

Browse files
author
Thomas Reggi
authored
fix: silently ignore session with unacknowledged write
NODE-1341
1 parent dfe7afa commit a053f4e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/core/sessions.js

+5
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,11 @@ function applySession(session, command, options) {
701701
return new MongoError('Cannot use a session that has ended');
702702
}
703703

704+
// SPEC-1019: silently ignore explicit session with unacknowledged write for backwards compatibility
705+
if (options && options.writeConcern && options.writeConcern.w === 0) {
706+
return;
707+
}
708+
704709
const serverSession = session.serverSession;
705710
serverSession.lastUse = now();
706711
command.lsid = serverSession.id;

test/functional/sessions.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict';
2+
3+
const withMonitoredClient = require('./shared').withMonitoredClient;
24
const expect = require('chai').expect;
35
const setupDatabase = require('./shared').setupDatabase;
46
const TestRunnerContext = require('./spec-runner').TestRunnerContext;
@@ -207,4 +209,25 @@ describe('Sessions', function() {
207209

208210
generateTopologyTests(testSuites, testContext, testFilter);
209211
});
212+
context('unacknowledged writes', () => {
213+
it('should not include session for unacknowledged writes', {
214+
metadata: { requires: { topology: 'single' } },
215+
test: withMonitoredClient('insert', { clientOptions: { w: 0 } }, function(
216+
client,
217+
events,
218+
done
219+
) {
220+
client
221+
.db('test')
222+
.collection('foo')
223+
.insertOne({ foo: 'bar' }, err => {
224+
expect(err).to.not.exist;
225+
const event = events[0];
226+
expect(event.command.writeConcern.w).to.equal(0);
227+
expect(event.command.lsid).to.equal(undefined);
228+
done();
229+
});
230+
})
231+
});
232+
});
210233
});

0 commit comments

Comments
 (0)