@@ -174,9 +174,22 @@ function createPool(poolAttrs, createPoolCb) {
174174 // be called by the database when a connection acquired from the pool doesn't
175175 // have the requested tag
176176 sessionCallback = poolAttrs . sessionCallback ;
177+
178+ // create an adjusted set of pool attributes to pass to the C layer; the
179+ // session callback must be removed if it is a JavaScript function and the
180+ // queue timeout is used to specify the maximum amount of time that the C
181+ // layer will wait for a connection to be returned; ordinarily since the
182+ // JavaScript layer never calls the C layer to get a connection unless one is
183+ // known to be available, this should not be needed, but in some cases (such
184+ // as when the maximum for a particular shard is specified) this may not be
185+ // known, so this prevents an unnecessarily long wait from taking place
186+ const adjustedPoolAttrs = Object . defineProperties ( { } ,
187+ Object . getOwnPropertyDescriptors ( poolAttrs ) ) ;
177188 if ( typeof poolAttrs . sessionCallback === 'function' ) {
178- poolAttrs = Object . assign ( { } , poolAttrs ) ;
179- delete poolAttrs . sessionCallback ;
189+ delete adjustedPoolAttrs . sessionCallback ;
190+ }
191+ if ( adjustedPoolAttrs . queueTimeout === undefined ) {
192+ adjustedPoolAttrs . queueTimeout = self . queueTimeout ;
180193 }
181194
182195 // Need to prevent another call in the same stack from succeeding, otherwise
@@ -186,7 +199,7 @@ function createPool(poolAttrs, createPoolCb) {
186199 tempUsedPoolAliases [ poolAlias ] = true ;
187200 }
188201
189- self . _createPool ( poolAttrs , function ( err , poolInst ) {
202+ self . _createPool ( adjustedPoolAttrs , function ( err , poolInst ) {
190203 if ( err ) {
191204 // We need to free this up since the creation of the pool failed.
192205 if ( poolAlias ) {
@@ -208,7 +221,6 @@ function createPool(poolAttrs, createPoolCb) {
208221 delete tempUsedPoolAliases [ poolAlias ] ;
209222 }
210223
211- poolAttrs . sessionCallback = sessionCallback ;
212224 poolInst . _setup ( poolAttrs , poolAlias , self ) ;
213225
214226 poolInst . on ( '_after_close' , function ( ) {
0 commit comments