Skip to content

✨ Add mongo driver version 7#170

Merged
dawidreedsy merged 1 commit intomasterfrom
bump-mongodb-version
Feb 24, 2026
Merged

✨ Add mongo driver version 7#170
dawidreedsy merged 1 commit intomasterfrom
bump-mongodb-version

Conversation

@dawidreedsy
Copy link
Contributor

No description provided.

@dawidreedsy dawidreedsy force-pushed the bump-mongodb-version branch 3 times, most recently from 3d7afc1 to b23030b Compare February 24, 2026 09:55
Comment on lines 229 to 253
@@ -233,7 +241,6 @@ describe('mongo db middleware', function() {
expect(request.options.testOptions).to.equal('yes');
expect(request.query._id).to.equal('test1');
next();
done();
});

var snapshot = {type: 'json0', id: 'test1', v: 1, data: {foo: 'bar'}};
@@ -242,6 +249,8 @@ describe('mongo db middleware', function() {
db.getSnapshot('testcollection', 'test1', null, {testOptions: 'yes'}, function(err, doc) {
if (err) return done(err);
expect(doc).to.exist;
expect(middlewareEntranceCount).to.equal(1);
done();
Copy link
Contributor Author

@dawidreedsy dawidreedsy Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not certain why this wasn’t visible earlier, but this PR:

introduced a migration to Promises.

When Promise.then is invoked, its callback is scheduled on the microtask queue. As a result, the db.getSnapshot call is deferred and executed after the current synchronous execution completes. This effectively allows it to proceed independently of the initial call stack.

Because of this change in execution order, the middleware can complete before db.getSnapshot has finished executing, which explains the errors we are getting with new mongodb version. Have no idea why it worked before...

  1) mongo db middleware
       beforeOverwrite
         has the expected properties on the request object:
     MongoClientClosedError: Operation interrupted because client was closed (and Mocha's done() called multiple times)
      at ConnectionPool.closeCheckedOutConnections (node_modules/mongodb7/lib/cmap/connection_pool.js:315:26)
      at Server.closeCheckedOutConnections (node_modules/mongodb7/lib/sdam/server.js:125:26)
      at Topology.closeCheckedOutConnections (node_modules/mongodb7/lib/sdam/topology.js:242:27)
      at MongoClient._close (node_modules/mongodb7/lib/mongo_client.js:342:24)
      at MongoClient.close (node_modules/mongodb7/lib/mongo_client.js:325:35)
      at /home/runner/work/sharedb-mongo/sharedb-mongo/index.js:32:391
      at /home/runner/work/sharedb-mongo/sharedb-mongo/index.js:27:1325

For example here:

sharedb-mongo/index.js

Lines 249 to 252 in fdda9b3

opCollection.insertOne(doc)
.then(function(result) {
callback(null, result);
}, callback);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh I do wish we were generally more resilient to tearing down tests while ShareDB is still working. It's so fiddly manually waiting for everything to finish all the time.

@coveralls
Copy link

Coverage Status

coverage: 92.725%. remained the same
when pulling fdda9b3 on bump-mongodb-version
into 02fbf78 on master.

@dawidreedsy dawidreedsy merged commit 6eb4105 into master Feb 24, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants