mongodb 3.4.0 → 3.5.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.
Files changed (45) hide show
  1. package/HISTORY.md +72 -0
  2. package/index.js +1 -0
  3. package/lib/bulk/common.js +1 -1
  4. package/lib/cmap/connection.js +369 -0
  5. package/lib/cmap/connection_pool.js +593 -0
  6. package/lib/cmap/errors.js +35 -0
  7. package/lib/cmap/events.js +154 -0
  8. package/lib/{core/cmap → cmap}/message_stream.js +19 -17
  9. package/lib/cmap/stream_description.js +45 -0
  10. package/lib/core/auth/scram.js +1 -1
  11. package/lib/core/connection/apm.js +24 -7
  12. package/lib/core/connection/connect.js +55 -26
  13. package/lib/core/connection/pool.js +3 -16
  14. package/lib/core/error.js +27 -10
  15. package/lib/core/index.js +1 -0
  16. package/lib/core/sdam/events.js +124 -0
  17. package/lib/core/sdam/monitor.js +251 -0
  18. package/lib/core/sdam/server.js +148 -198
  19. package/lib/core/sdam/server_description.js +6 -4
  20. package/lib/core/sdam/server_selection.js +0 -91
  21. package/lib/core/sdam/topology.js +162 -136
  22. package/lib/core/sdam/topology_description.js +10 -8
  23. package/lib/core/sessions.js +16 -3
  24. package/lib/core/topologies/mongos.js +5 -13
  25. package/lib/core/topologies/replset.js +5 -10
  26. package/lib/core/topologies/server.js +9 -4
  27. package/lib/core/topologies/shared.js +0 -60
  28. package/lib/core/transactions.js +18 -7
  29. package/lib/core/uri_parser.js +3 -0
  30. package/lib/core/utils.js +84 -18
  31. package/lib/core/wireprotocol/command.js +2 -9
  32. package/lib/gridfs-stream/upload.js +1 -1
  33. package/lib/mongo_client.js +6 -6
  34. package/lib/operations/connect.js +118 -49
  35. package/lib/operations/execute_operation.js +31 -40
  36. package/lib/operations/find_one.js +13 -9
  37. package/lib/topologies/mongos.js +2 -9
  38. package/lib/topologies/native_topology.js +2 -6
  39. package/lib/topologies/replset.js +2 -9
  40. package/lib/topologies/server.js +2 -9
  41. package/lib/topologies/topology_base.js +4 -25
  42. package/lib/utils.js +11 -2
  43. package/package.json +3 -2
  44. package/lib/core/cmap/connection.js +0 -220
  45. package/lib/core/sdam/monitoring.js +0 -241
@@ -0,0 +1,593 @@
1
+ 'use strict';
2
+
3
+ const Denque = require('denque');
4
+ const EventEmitter = require('events').EventEmitter;
5
+ const Logger = require('../core/connection/logger');
6
+ const makeCounter = require('../utils').makeCounter;
7
+ const MongoError = require('../core/error').MongoError;
8
+ const Connection = require('./connection').Connection;
9
+ const eachAsync = require('../core/utils').eachAsync;
10
+ const connect = require('../core/connection/connect');
11
+ const relayEvents = require('../core/utils').relayEvents;
12
+
13
+ const errors = require('./errors');
14
+ const PoolClosedError = errors.PoolClosedError;
15
+ const WaitQueueTimeoutError = errors.WaitQueueTimeoutError;
16
+
17
+ const events = require('./events');
18
+ const ConnectionPoolCreatedEvent = events.ConnectionPoolCreatedEvent;
19
+ const ConnectionPoolClosedEvent = events.ConnectionPoolClosedEvent;
20
+ const ConnectionCreatedEvent = events.ConnectionCreatedEvent;
21
+ const ConnectionReadyEvent = events.ConnectionReadyEvent;
22
+ const ConnectionClosedEvent = events.ConnectionClosedEvent;
23
+ const ConnectionCheckOutStartedEvent = events.ConnectionCheckOutStartedEvent;
24
+ const ConnectionCheckOutFailedEvent = events.ConnectionCheckOutFailedEvent;
25
+ const ConnectionCheckedOutEvent = events.ConnectionCheckedOutEvent;
26
+ const ConnectionCheckedInEvent = events.ConnectionCheckedInEvent;
27
+ const ConnectionPoolClearedEvent = events.ConnectionPoolClearedEvent;
28
+
29
+ const kLogger = Symbol('logger');
30
+ const kConnections = Symbol('connections');
31
+ const kPermits = Symbol('permits');
32
+ const kMinPoolSizeTimer = Symbol('minPoolSizeTimer');
33
+ const kGeneration = Symbol('generation');
34
+ const kConnectionCounter = Symbol('connectionCounter');
35
+ const kCancellationToken = Symbol('cancellationToken');
36
+ const kWaitQueue = Symbol('waitQueue');
37
+ const kCancelled = Symbol('cancelled');
38
+
39
+ const VALID_POOL_OPTIONS = new Set([
40
+ // `connect` options
41
+ 'ssl',
42
+ 'bson',
43
+ 'connectionType',
44
+ 'monitorCommands',
45
+ 'socketTimeout',
46
+ 'credentials',
47
+ 'compression',
48
+
49
+ // node Net options
50
+ 'host',
51
+ 'port',
52
+ 'localAddress',
53
+ 'localPort',
54
+ 'family',
55
+ 'hints',
56
+ 'lookup',
57
+ 'path',
58
+
59
+ // node TLS options
60
+ 'ca',
61
+ 'cert',
62
+ 'sigalgs',
63
+ 'ciphers',
64
+ 'clientCertEngine',
65
+ 'crl',
66
+ 'dhparam',
67
+ 'ecdhCurve',
68
+ 'honorCipherOrder',
69
+ 'key',
70
+ 'privateKeyEngine',
71
+ 'privateKeyIdentifier',
72
+ 'maxVersion',
73
+ 'minVersion',
74
+ 'passphrase',
75
+ 'pfx',
76
+ 'secureOptions',
77
+ 'secureProtocol',
78
+ 'sessionIdContext',
79
+ 'allowHalfOpen',
80
+ 'rejectUnauthorized',
81
+ 'pskCallback',
82
+ 'ALPNProtocols',
83
+ 'servername',
84
+ 'checkServerIdentity',
85
+ 'session',
86
+ 'minDHSize',
87
+ 'secureContext',
88
+
89
+ // spec options
90
+ 'maxPoolSize',
91
+ 'minPoolSize',
92
+ 'maxIdleTimeMS',
93
+ 'waitQueueTimeoutMS'
94
+ ]);
95
+
96
+ function resolveOptions(options, defaults) {
97
+ const newOptions = Array.from(VALID_POOL_OPTIONS).reduce((obj, key) => {
98
+ if (options.hasOwnProperty(key)) {
99
+ obj[key] = options[key];
100
+ }
101
+
102
+ return obj;
103
+ }, {});
104
+
105
+ return Object.freeze(Object.assign({}, defaults, newOptions));
106
+ }
107
+
108
+ /**
109
+ * Configuration options for drivers wrapping the node driver.
110
+ *
111
+ * @typedef {Object} ConnectionPoolOptions
112
+ * @property
113
+ * @property {string} [host] The host to connect to
114
+ * @property {number} [port] The port to connect to
115
+ * @property {bson} [bson] The BSON instance to use for new connections
116
+ * @property {number} [maxPoolSize=100] The maximum number of connections that may be associated with a pool at a given time. This includes in use and available connections.
117
+ * @property {number} [minPoolSize=0] The minimum number of connections that MUST exist at any moment in a single connection pool.
118
+ * @property {number} [maxIdleTimeMS] The maximum amount of time a connection should remain idle in the connection pool before being marked idle.
119
+ * @property {number} [waitQueueTimeoutMS=0] The maximum amount of time operation execution should wait for a connection to become available. The default is 0 which means there is no limit.
120
+ */
121
+
122
+ /**
123
+ * A pool of connections which dynamically resizes, and emit events related to pool activity
124
+ *
125
+ * @property {number} generation An integer representing the SDAM generation of the pool
126
+ * @property {number} totalConnectionCount An integer expressing how many total connections (active + in use) the pool currently has
127
+ * @property {number} availableConnectionCount An integer expressing how many connections are currently available in the pool.
128
+ * @property {string} address The address of the endpoint the pool is connected to
129
+ *
130
+ * @emits ConnectionPool#connectionPoolCreated
131
+ * @emits ConnectionPool#connectionPoolClosed
132
+ * @emits ConnectionPool#connectionCreated
133
+ * @emits ConnectionPool#connectionReady
134
+ * @emits ConnectionPool#connectionClosed
135
+ * @emits ConnectionPool#connectionCheckOutStarted
136
+ * @emits ConnectionPool#connectionCheckOutFailed
137
+ * @emits ConnectionPool#connectionCheckedOut
138
+ * @emits ConnectionPool#connectionCheckedIn
139
+ * @emits ConnectionPool#connectionPoolCleared
140
+ */
141
+ class ConnectionPool extends EventEmitter {
142
+ /**
143
+ * Create a new Connection Pool
144
+ *
145
+ * @param {ConnectionPoolOptions} options
146
+ */
147
+ constructor(options) {
148
+ super();
149
+ options = options || {};
150
+
151
+ this.closed = false;
152
+ this.options = resolveOptions(options, {
153
+ connectionType: Connection,
154
+ maxPoolSize: typeof options.maxPoolSize === 'number' ? options.maxPoolSize : 100,
155
+ minPoolSize: typeof options.minPoolSize === 'number' ? options.minPoolSize : 0,
156
+ maxIdleTimeMS: typeof options.maxIdleTimeMS === 'number' ? options.maxIdleTimeMS : 0,
157
+ waitQueueTimeoutMS:
158
+ typeof options.waitQueueTimeoutMS === 'number' ? options.waitQueueTimeoutMS : 0,
159
+ autoEncrypter: options.autoEncrypter,
160
+ metadata: options.metadata
161
+ });
162
+
163
+ if (options.minSize > options.maxSize) {
164
+ throw new TypeError(
165
+ 'Connection pool minimum size must not be greater than maxiumum pool size'
166
+ );
167
+ }
168
+
169
+ this[kLogger] = Logger('ConnectionPool', options);
170
+ this[kConnections] = new Denque();
171
+ this[kPermits] = this.options.maxPoolSize;
172
+ this[kMinPoolSizeTimer] = undefined;
173
+ this[kGeneration] = 0;
174
+ this[kConnectionCounter] = makeCounter(1);
175
+ this[kCancellationToken] = new EventEmitter();
176
+ this[kCancellationToken].setMaxListeners(Infinity);
177
+ this[kWaitQueue] = new Denque();
178
+
179
+ process.nextTick(() => {
180
+ this.emit('connectionPoolCreated', new ConnectionPoolCreatedEvent(this));
181
+ ensureMinPoolSize(this);
182
+ });
183
+ }
184
+
185
+ get address() {
186
+ return `${this.options.host}:${this.options.port}`;
187
+ }
188
+
189
+ get generation() {
190
+ return this[kGeneration];
191
+ }
192
+
193
+ get totalConnectionCount() {
194
+ return this[kConnections].length + (this.options.maxPoolSize - this[kPermits]);
195
+ }
196
+
197
+ get availableConnectionCount() {
198
+ return this[kConnections].length;
199
+ }
200
+
201
+ /**
202
+ * Check a connection out of this pool. The connection will continue to be tracked, but no reference to it
203
+ * will be held by the pool. This means that if a connection is checked out it MUST be checked back in or
204
+ * explicitly destroyed by the new owner.
205
+ *
206
+ * @param {ConnectionPool~checkOutCallback} callback
207
+ */
208
+ checkOut(callback) {
209
+ this.emit('connectionCheckOutStarted', new ConnectionCheckOutStartedEvent(this));
210
+
211
+ if (this.closed) {
212
+ this.emit('connectionCheckOutFailed', new ConnectionCheckOutFailedEvent(this, 'poolClosed'));
213
+ callback(new PoolClosedError(this));
214
+ return;
215
+ }
216
+
217
+ // add this request to the wait queue
218
+ const waitQueueMember = { callback };
219
+
220
+ const pool = this;
221
+ const waitQueueTimeoutMS = this.options.waitQueueTimeoutMS;
222
+ if (waitQueueTimeoutMS) {
223
+ waitQueueMember.timer = setTimeout(() => {
224
+ waitQueueMember[kCancelled] = true;
225
+ waitQueueMember.timer = undefined;
226
+
227
+ pool.emit('connectionCheckOutFailed', new ConnectionCheckOutFailedEvent(pool, 'timeout'));
228
+ waitQueueMember.callback(new WaitQueueTimeoutError(pool));
229
+ }, waitQueueTimeoutMS);
230
+ }
231
+
232
+ // place the member at the end of the wait queue
233
+ this[kWaitQueue].push(waitQueueMember);
234
+
235
+ // process the wait queue
236
+ processWaitQueue(this);
237
+ }
238
+
239
+ /**
240
+ * Check a connection into the pool.
241
+ *
242
+ * @param {Connection} connection The connection to check in
243
+ */
244
+ checkIn(connection) {
245
+ const poolClosed = this.closed;
246
+ const stale = connectionIsStale(this, connection);
247
+ const willDestroy = !!(poolClosed || stale || connection.closed);
248
+
249
+ // Properly adjust state of connection
250
+ if (!willDestroy) {
251
+ connection.markAvailable();
252
+
253
+ this[kConnections].push(connection);
254
+ }
255
+
256
+ this.emit('connectionCheckedIn', new ConnectionCheckedInEvent(this, connection));
257
+
258
+ if (willDestroy) {
259
+ const reason = connection.closed ? 'error' : poolClosed ? 'poolClosed' : 'stale';
260
+ destroyConnection(this, connection, reason);
261
+ }
262
+
263
+ processWaitQueue(this);
264
+ }
265
+
266
+ /**
267
+ * Clear the pool
268
+ *
269
+ * Pool reset is handled by incrementing the pool's generation count. Any existing connection of a
270
+ * previous generation will eventually be pruned during subsequent checkouts.
271
+ */
272
+ clear() {
273
+ this[kGeneration] += 1;
274
+ this.emit('connectionPoolCleared', new ConnectionPoolClearedEvent(this));
275
+ }
276
+
277
+ /**
278
+ * Close the pool
279
+ *
280
+ * @param {object} [options] Optional settings
281
+ * @param {boolean} [options.force] Force close connections
282
+ * @param {Function} callback
283
+ */
284
+ close(options, callback) {
285
+ if (typeof options === 'function') {
286
+ callback = options;
287
+ }
288
+
289
+ options = Object.assign({ force: false }, options);
290
+ if (this.closed) {
291
+ return callback();
292
+ }
293
+
294
+ // immediately cancel any in-flight connections
295
+ this[kCancellationToken].emit('cancel');
296
+
297
+ // drain the wait queue
298
+ while (this[kWaitQueue].length) {
299
+ const waitQueueMember = this[kWaitQueue].pop();
300
+ clearTimeout(waitQueueMember.timer);
301
+ if (!waitQueueMember[kCancelled]) {
302
+ waitQueueMember.callback(new MongoError('connection pool closed'));
303
+ }
304
+ }
305
+
306
+ // clear the min pool size timer
307
+ if (this[kMinPoolSizeTimer]) {
308
+ clearTimeout(this[kMinPoolSizeTimer]);
309
+ }
310
+
311
+ // end the connection counter
312
+ if (typeof this[kConnectionCounter].return === 'function') {
313
+ this[kConnectionCounter].return();
314
+ }
315
+
316
+ // mark the pool as closed immediately
317
+ this.closed = true;
318
+
319
+ eachAsync(
320
+ this[kConnections].toArray(),
321
+ (conn, cb) => {
322
+ this.emit('connectionClosed', new ConnectionClosedEvent(this, conn, 'poolClosed'));
323
+ conn.destroy(options, cb);
324
+ },
325
+ err => {
326
+ this[kConnections].clear();
327
+ this.emit('connectionPoolClosed', new ConnectionPoolClosedEvent(this));
328
+ callback(err);
329
+ }
330
+ );
331
+ }
332
+
333
+ /**
334
+ * Runs a lambda with an implicitly checked out connection, checking that connection back in when the lambda
335
+ * has completed by calling back.
336
+ *
337
+ * NOTE: please note the required signature of `fn`
338
+ *
339
+ * @param {ConnectionPool~withConnectionCallback} fn A function which operates on a managed connection
340
+ * @param {Function} callback The original callback
341
+ * @return {Promise}
342
+ */
343
+ withConnection(fn, callback) {
344
+ this.checkOut((err, conn) => {
345
+ // don't callback with `err` here, we might want to act upon it inside `fn`
346
+
347
+ fn(err, conn, (fnErr, result) => {
348
+ if (typeof callback === 'function') {
349
+ if (fnErr) {
350
+ callback(fnErr);
351
+ } else {
352
+ callback(undefined, result);
353
+ }
354
+ }
355
+
356
+ if (conn) {
357
+ this.checkIn(conn);
358
+ }
359
+ });
360
+ });
361
+ }
362
+ }
363
+
364
+ function ensureMinPoolSize(pool) {
365
+ if (pool.closed) {
366
+ return;
367
+ }
368
+
369
+ const minPoolSize = pool.options.minPoolSize;
370
+ for (let i = pool.totalConnectionCount; i < minPoolSize; ++i) {
371
+ createConnection(pool);
372
+ }
373
+
374
+ pool[kMinPoolSizeTimer] = setTimeout(() => ensureMinPoolSize(pool), 10);
375
+ }
376
+
377
+ function connectionIsStale(pool, connection) {
378
+ return connection.generation !== pool[kGeneration];
379
+ }
380
+
381
+ function connectionIsIdle(pool, connection) {
382
+ return !!(pool.options.maxIdleTimeMS && connection.idleTime > pool.options.maxIdleTimeMS);
383
+ }
384
+
385
+ function createConnection(pool, callback) {
386
+ const connectOptions = Object.assign(
387
+ {
388
+ id: pool[kConnectionCounter].next().value,
389
+ generation: pool[kGeneration]
390
+ },
391
+ pool.options
392
+ );
393
+
394
+ pool[kPermits]--;
395
+ connect(connectOptions, pool[kCancellationToken], (err, connection) => {
396
+ if (err) {
397
+ pool[kPermits]++;
398
+ pool[kLogger].debug(`connection attempt failed with error [${JSON.stringify(err)}]`);
399
+ if (typeof callback === 'function') {
400
+ callback(err);
401
+ }
402
+
403
+ return;
404
+ }
405
+
406
+ // The pool might have closed since we started trying to create a connection
407
+ if (pool.closed) {
408
+ connection.destroy({ force: true });
409
+ return;
410
+ }
411
+
412
+ // forward all events from the connection to the pool
413
+ relayEvents(connection, pool, [
414
+ 'commandStarted',
415
+ 'commandFailed',
416
+ 'commandSucceeded',
417
+ 'clusterTimeReceived'
418
+ ]);
419
+
420
+ pool.emit('connectionCreated', new ConnectionCreatedEvent(pool, connection));
421
+
422
+ connection.markAvailable();
423
+ pool.emit('connectionReady', new ConnectionReadyEvent(pool, connection));
424
+
425
+ // if a callback has been provided, check out the connection immediately
426
+ if (typeof callback === 'function') {
427
+ callback(undefined, connection);
428
+ return;
429
+ }
430
+
431
+ // otherwise add it to the pool for later acquisition, and try to process the wait queue
432
+ pool[kConnections].push(connection);
433
+ processWaitQueue(pool);
434
+ });
435
+ }
436
+
437
+ function destroyConnection(pool, connection, reason) {
438
+ pool.emit('connectionClosed', new ConnectionClosedEvent(pool, connection, reason));
439
+
440
+ // allow more connections to be created
441
+ pool[kPermits]++;
442
+
443
+ // destroy the connection
444
+ process.nextTick(() => connection.destroy());
445
+ }
446
+
447
+ function processWaitQueue(pool) {
448
+ if (pool.closed) {
449
+ return;
450
+ }
451
+
452
+ while (pool[kWaitQueue].length && pool.availableConnectionCount) {
453
+ const waitQueueMember = pool[kWaitQueue].peekFront();
454
+ if (waitQueueMember[kCancelled]) {
455
+ pool[kWaitQueue].shift();
456
+ continue;
457
+ }
458
+
459
+ const connection = pool[kConnections].shift();
460
+ const isStale = connectionIsStale(pool, connection);
461
+ const isIdle = connectionIsIdle(pool, connection);
462
+ if (!isStale && !isIdle && !connection.closed) {
463
+ pool.emit('connectionCheckedOut', new ConnectionCheckedOutEvent(pool, connection));
464
+ clearTimeout(waitQueueMember.timer);
465
+ pool[kWaitQueue].shift();
466
+ waitQueueMember.callback(undefined, connection);
467
+ return;
468
+ }
469
+
470
+ const reason = connection.closed ? 'error' : isStale ? 'stale' : 'idle';
471
+ destroyConnection(pool, connection, reason);
472
+ }
473
+
474
+ const maxPoolSize = pool.options.maxPoolSize;
475
+ if (pool[kWaitQueue].length && (maxPoolSize <= 0 || pool.totalConnectionCount < maxPoolSize)) {
476
+ createConnection(pool, (err, connection) => {
477
+ const waitQueueMember = pool[kWaitQueue].shift();
478
+ if (waitQueueMember == null) {
479
+ if (err == null) {
480
+ pool[kConnections].push(connection);
481
+ }
482
+
483
+ return;
484
+ }
485
+
486
+ if (waitQueueMember[kCancelled]) {
487
+ return;
488
+ }
489
+
490
+ if (err) {
491
+ pool.emit('connectionCheckOutFailed', new ConnectionCheckOutFailedEvent(pool, err));
492
+ } else {
493
+ pool.emit('connectionCheckedOut', new ConnectionCheckedOutEvent(pool, connection));
494
+ }
495
+
496
+ clearTimeout(waitQueueMember.timer);
497
+ waitQueueMember.callback(err, connection);
498
+ });
499
+
500
+ return;
501
+ }
502
+ }
503
+
504
+ /**
505
+ * A callback provided to `withConnection`
506
+ *
507
+ * @callback ConnectionPool~withConnectionCallback
508
+ * @param {MongoError} error An error instance representing the error during the execution.
509
+ * @param {Connection} connection The managed connection which was checked out of the pool.
510
+ * @param {Function} callback A function to call back after connection management is complete
511
+ */
512
+
513
+ /**
514
+ * A callback provided to `checkOut`
515
+ *
516
+ * @callback ConnectionPool~checkOutCallback
517
+ * @param {MongoError} error An error instance representing the error during checkout
518
+ * @param {Connection} connection A connection from the pool
519
+ */
520
+
521
+ /**
522
+ * Emitted once when the connection pool is created
523
+ *
524
+ * @event ConnectionPool#connectionPoolCreated
525
+ * @type {PoolCreatedEvent}
526
+ */
527
+
528
+ /**
529
+ * Emitted once when the connection pool is closed
530
+ *
531
+ * @event ConnectionPool#connectionPoolClosed
532
+ * @type {PoolClosedEvent}
533
+ */
534
+
535
+ /**
536
+ * Emitted each time a connection is created
537
+ *
538
+ * @event ConnectionPool#connectionCreated
539
+ * @type {ConnectionCreatedEvent}
540
+ */
541
+
542
+ /**
543
+ * Emitted when a connection becomes established, and is ready to use
544
+ *
545
+ * @event ConnectionPool#connectionReady
546
+ * @type {ConnectionReadyEvent}
547
+ */
548
+
549
+ /**
550
+ * Emitted when a connection is closed
551
+ *
552
+ * @event ConnectionPool#connectionClosed
553
+ * @type {ConnectionClosedEvent}
554
+ */
555
+
556
+ /**
557
+ * Emitted when an attempt to check out a connection begins
558
+ *
559
+ * @event ConnectionPool#connectionCheckOutStarted
560
+ * @type {ConnectionCheckOutStartedEvent}
561
+ */
562
+
563
+ /**
564
+ * Emitted when an attempt to check out a connection fails
565
+ *
566
+ * @event ConnectionPool#connectionCheckOutFailed
567
+ * @type {ConnectionCheckOutFailedEvent}
568
+ */
569
+
570
+ /**
571
+ * Emitted each time a connection is successfully checked out of the connection pool
572
+ *
573
+ * @event ConnectionPool#connectionCheckedOut
574
+ * @type {ConnectionCheckedOutEvent}
575
+ */
576
+
577
+ /**
578
+ * Emitted each time a connection is successfully checked into the connection pool
579
+ *
580
+ * @event ConnectionPool#connectionCheckedIn
581
+ * @type {ConnectionCheckedInEvent}
582
+ */
583
+
584
+ /**
585
+ * Emitted each time the connection pool is cleared and it's generation incremented
586
+ *
587
+ * @event ConnectionPool#connectionPoolCleared
588
+ * @type {PoolClearedEvent}
589
+ */
590
+
591
+ module.exports = {
592
+ ConnectionPool
593
+ };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+ const MongoError = require('../core/error').MongoError;
3
+
4
+ /**
5
+ * An error indicating a connection pool is closed
6
+ *
7
+ * @property {string} address The address of the connection pool
8
+ * @extends MongoError
9
+ */
10
+ class PoolClosedError extends MongoError {
11
+ constructor(pool) {
12
+ super('Attempted to check out a connection from closed connection pool');
13
+ this.name = 'MongoPoolClosedError';
14
+ this.address = pool.address;
15
+ }
16
+ }
17
+
18
+ /**
19
+ * An error thrown when a request to check out a connection times out
20
+ *
21
+ * @property {string} address The address of the connection pool
22
+ * @extends MongoError
23
+ */
24
+ class WaitQueueTimeoutError extends MongoError {
25
+ constructor(pool) {
26
+ super('Timed out while checking out a connection from connection pool');
27
+ this.name = 'MongoWaitQueueTimeoutError';
28
+ this.address = pool.address;
29
+ }
30
+ }
31
+
32
+ module.exports = {
33
+ PoolClosedError,
34
+ WaitQueueTimeoutError
35
+ };