mongodb 3.6.1 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/HISTORY.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ <a name="3.6.2"></a>
6
+ ## [3.6.2](https://github.com/mongodb/node-mongodb-native/compare/v3.6.1...v3.6.2) (2020-09-10)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * allow event loop to process during wait queue processing ([#2537](https://github.com/mongodb/node-mongodb-native/issues/2537)) ([4e03dfa](https://github.com/mongodb/node-mongodb-native/commit/4e03dfa))
12
+
13
+
14
+
5
15
  <a name="3.6.1"></a>
6
16
  ## [3.6.1](https://github.com/mongodb/node-mongodb-native/compare/v3.6.0...v3.6.1) (2020-09-02)
7
17
 
@@ -218,7 +218,6 @@ class ConnectionPool extends EventEmitter {
218
218
  return;
219
219
  }
220
220
 
221
- // add this request to the wait queue
222
221
  const waitQueueMember = { callback };
223
222
 
224
223
  const pool = this;
@@ -233,11 +232,8 @@ class ConnectionPool extends EventEmitter {
233
232
  }, waitQueueTimeoutMS);
234
233
  }
235
234
 
236
- // place the member at the end of the wait queue
237
235
  this[kWaitQueue].push(waitQueueMember);
238
-
239
- // process the wait queue
240
- processWaitQueue(this);
236
+ setImmediate(() => processWaitQueue(this));
241
237
  }
242
238
 
243
239
  /**
@@ -250,10 +246,8 @@ class ConnectionPool extends EventEmitter {
250
246
  const stale = connectionIsStale(this, connection);
251
247
  const willDestroy = !!(poolClosed || stale || connection.closed);
252
248
 
253
- // Properly adjust state of connection
254
249
  if (!willDestroy) {
255
250
  connection.markAvailable();
256
-
257
251
  this[kConnections].push(connection);
258
252
  }
259
253
 
@@ -264,7 +258,7 @@ class ConnectionPool extends EventEmitter {
264
258
  destroyConnection(this, connection, reason);
265
259
  }
266
260
 
267
- processWaitQueue(this);
261
+ setImmediate(() => processWaitQueue(this));
268
262
  }
269
263
 
270
264
  /**
@@ -434,7 +428,7 @@ function createConnection(pool, callback) {
434
428
 
435
429
  // otherwise add it to the pool for later acquisition, and try to process the wait queue
436
430
  pool[kConnections].push(connection);
437
- processWaitQueue(pool);
431
+ setImmediate(() => processWaitQueue(pool));
438
432
  });
439
433
  }
440
434
 
@@ -445,7 +439,7 @@ function destroyConnection(pool, connection, reason) {
445
439
  pool[kPermits]++;
446
440
 
447
441
  // destroy the connection
448
- process.nextTick(() => connection.destroy());
442
+ setImmediate(() => connection.destroy());
449
443
  }
450
444
 
451
445
  function processWaitQueue(pool) {
@@ -745,9 +745,10 @@ function nextFunction(self, callback) {
745
745
 
746
746
  if (self.cursorState.limit > 0 && self.cursorState.currentLimit >= self.cursorState.limit) {
747
747
  // Ensure we kill the cursor on the server
748
- self.kill();
749
- // Set cursor in dead and notified state
750
- return setCursorDeadAndNotified(self, callback);
748
+ self.kill(() =>
749
+ // Set cursor in dead and notified state
750
+ setCursorDeadAndNotified(self, callback)
751
+ );
751
752
  } else if (
752
753
  self.cursorState.cursorIndex === self.cursorState.documents.length &&
753
754
  !Long.ZERO.equals(self.cursorState.cursorId)
@@ -827,9 +828,12 @@ function nextFunction(self, callback) {
827
828
  } else {
828
829
  if (self.cursorState.limit > 0 && self.cursorState.currentLimit >= self.cursorState.limit) {
829
830
  // Ensure we kill the cursor on the server
830
- self.kill();
831
- // Set cursor in dead and notified state
832
- return setCursorDeadAndNotified(self, callback);
831
+ self.kill(() =>
832
+ // Set cursor in dead and notified state
833
+ setCursorDeadAndNotified(self, callback)
834
+ );
835
+
836
+ return;
833
837
  }
834
838
 
835
839
  // Increment the current cursor limit
@@ -841,11 +845,14 @@ function nextFunction(self, callback) {
841
845
  // Doc overflow
842
846
  if (!doc || doc.$err) {
843
847
  // Ensure we kill the cursor on the server
844
- self.kill();
845
- // Set cursor in dead and notified state
846
- return setCursorDeadAndNotified(self, function() {
847
- handleCallback(callback, new MongoError(doc ? doc.$err : undefined));
848
- });
848
+ self.kill(() =>
849
+ // Set cursor in dead and notified state
850
+ setCursorDeadAndNotified(self, function() {
851
+ handleCallback(callback, new MongoError(doc ? doc.$err : undefined));
852
+ })
853
+ );
854
+
855
+ return;
849
856
  }
850
857
 
851
858
  // Transform the doc with passed in transformation method if provided
@@ -13,6 +13,7 @@ const Transaction = require('./transactions').Transaction;
13
13
  const TxnState = require('./transactions').TxnState;
14
14
  const isPromiseLike = require('./utils').isPromiseLike;
15
15
  const ReadPreference = require('./topologies/read_preference');
16
+ const maybePromise = require('../utils').maybePromise;
16
17
  const isTransactionCommand = require('./transactions').isTransactionCommand;
17
18
  const resolveClusterTime = require('./topologies/shared').resolveClusterTime;
18
19
  const isSharded = require('./wireprotocol/shared').isSharded;
@@ -125,25 +126,36 @@ class ClientSession extends EventEmitter {
125
126
  if (typeof options === 'function') (callback = options), (options = {});
126
127
  options = options || {};
127
128
 
128
- if (this.hasEnded) {
129
- if (typeof callback === 'function') callback(null, null);
130
- return;
131
- }
129
+ const session = this;
130
+ return maybePromise(this, callback, done => {
131
+ if (session.hasEnded) {
132
+ return done();
133
+ }
132
134
 
133
- if (this.serverSession && this.inTransaction()) {
134
- this.abortTransaction(); // pass in callback?
135
- }
135
+ function completeEndSession() {
136
+ // release the server session back to the pool
137
+ session.sessionPool.release(session.serverSession);
138
+ session[kServerSession] = undefined;
136
139
 
137
- // release the server session back to the pool
138
- this.sessionPool.release(this.serverSession);
139
- this[kServerSession] = undefined;
140
+ // mark the session as ended, and emit a signal
141
+ session.hasEnded = true;
142
+ session.emit('ended', session);
143
+
144
+ // spec indicates that we should ignore all errors for `endSessions`
145
+ done();
146
+ }
147
+
148
+ if (session.serverSession && session.inTransaction()) {
149
+ session.abortTransaction(err => {
150
+ if (err) return done(err);
151
+ completeEndSession();
152
+ });
140
153
 
141
- // mark the session as ended, and emit a signal
142
- this.hasEnded = true;
143
- this.emit('ended', this);
154
+ return;
155
+ }
144
156
 
145
- // spec indicates that we should ignore all errors for `endSessions`
146
- if (typeof callback === 'function') callback(null, null);
157
+ completeEndSession();
158
+ });
147
159
  }
148
160
 
149
161
  /**
@@ -227,16 +239,7 @@ class ClientSession extends EventEmitter {
227
239
  * @return {Promise} A promise is returned if no callback is provided
228
240
  */
229
241
  commitTransaction(callback) {
230
- if (typeof callback === 'function') {
231
- endTransaction(this, 'commitTransaction', callback);
232
- return;
233
- }
234
-
235
- return new Promise((resolve, reject) => {
236
- endTransaction(this, 'commitTransaction', (err, reply) =>
237
- err ? reject(err) : resolve(reply)
238
- );
239
- });
242
+ return maybePromise(this, callback, done => endTransaction(this, 'commitTransaction', done));
240
243
  }
241
244
 
242
245
  /**
@@ -246,16 +249,7 @@ class ClientSession extends EventEmitter {
246
249
  * @return {Promise} A promise is returned if no callback is provided
247
250
  */
248
251
  abortTransaction(callback) {
249
- if (typeof callback === 'function') {
250
- endTransaction(this, 'abortTransaction', callback);
251
- return;
252
- }
253
-
254
- return new Promise((resolve, reject) => {
255
- endTransaction(this, 'abortTransaction', (err, reply) =>
256
- err ? reject(err) : resolve(reply)
257
- );
258
- });
252
+ return maybePromise(this, callback, done => endTransaction(this, 'abortTransaction', done));
259
253
  }
260
254
 
261
255
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "3.6.1",
3
+ "version": "3.6.2",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -24,7 +24,7 @@
24
24
  "bson-ext": "^2.0.0"
25
25
  },
26
26
  "dependencies": {
27
- "bl": "^2.2.0",
27
+ "bl": "^2.2.1",
28
28
  "bson": "^1.1.4",
29
29
  "denque": "^1.4.1",
30
30
  "require_optional": "^1.0.1",