File tree Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -255,6 +255,9 @@ addition to those options pools accept a few extras:
255
255
pool will immediately call back with an error. (Default: ` true ` )
256
256
* ` connectionLimit ` : The maximum number of connections to create at once.
257
257
(Default: ` 10 ` )
258
+ * ` queueLimit ` : The maximum number of connection requests the pool will queue
259
+ before returning an error from ` getConnection ` . If set to ` 0 ` , there is no
260
+ limit to the number of queued connection requests. (Default: ` 0 ` )
258
261
259
262
## Switching users / altering connection state
260
263
Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ Pool.prototype.getConnection = function (cb) {
47
47
return cb ( new Error ( 'No connections available.' ) ) ;
48
48
}
49
49
50
+ if ( this . config . queueLimit && this . _connectionQueue . length >= this . config . queueLimit ) {
51
+ return cb ( new Error ( 'Queue limit reached.' ) ) ;
52
+ }
53
+
50
54
this . _connectionQueue . push ( cb ) ;
51
55
} ;
52
56
Original file line number Diff line number Diff line change @@ -11,4 +11,7 @@ function PoolConfig(options) {
11
11
this . connectionLimit = ( options . connectionLimit === undefined )
12
12
? 10
13
13
: Number ( options . connectionLimit ) ;
14
+ this . queueLimit = ( options . queueLimit === undefined )
15
+ ? 0
16
+ : Number ( options . queueLimit ) ;
14
17
}
Original file line number Diff line number Diff line change
1
+ var common = require ( '../../common' ) ;
2
+ var assert = require ( 'assert' ) ;
3
+ var pool = common . createPool ( {
4
+ connectionLimit : 1 ,
5
+ queueLimit : 1 ,
6
+ waitForConnections : true
7
+ } ) ;
8
+
9
+ // First connection we get right away
10
+ pool . getConnection ( function ( err , connection ) {
11
+ connection . end ( )
12
+ } )
13
+
14
+ // Second connection request goes into the queue
15
+ pool . getConnection ( function ( err , connection ) {
16
+ connection . end ( )
17
+ pool . end ( )
18
+ } )
19
+
20
+ // Third connection request gets refused, since the queue is full
21
+ var thirdGetErr
22
+ pool . getConnection ( function ( err , connection ) {
23
+ thirdGetErr = err
24
+ } )
25
+
26
+ process . on ( 'exit' , function ( ) {
27
+ assert . equal ( thirdGetErr . message , 'Queue limit reached.' )
28
+ } )
You can’t perform that action at this time.
0 commit comments