@@ -26,6 +26,7 @@ import {
2626 ACCESS_MODE_READ ,
2727 ACCESS_MODE_WRITE ,
2828 FETCH_ALL ,
29+ DEFAULT_CONNECTION_TIMEOUT_MILLIS ,
2930 DEFAULT_POOL_ACQUISITION_TIMEOUT ,
3031 DEFAULT_POOL_MAX_SIZE
3132} from './internal/constants'
@@ -131,12 +132,15 @@ class Driver {
131132 createSession : CreateSession = args => new Session ( args )
132133 ) {
133134 sanitizeConfig ( config )
134- validateConfig ( config )
135+
136+ const log = Logger . create ( config )
137+
138+ validateConfig ( config , log )
135139
136140 this . _id = idGenerator ++
137141 this . _meta = meta
138142 this . _config = config
139- this . _log = Logger . create ( config )
143+ this . _log = log ;
140144 this . _createConnectionProvider = createConnectonProvider
141145 this . _createSession = createSession
142146
@@ -366,13 +370,22 @@ class Driver {
366370 * @private
367371 * @returns {Object } the given config.
368372 */
369- function validateConfig ( config : any ) : any {
373+ function validateConfig ( config : any , log : Logger ) : any {
370374 const resolver = config . resolver
371375 if ( resolver && typeof resolver !== 'function' ) {
372376 throw new TypeError (
373377 `Configured resolver should be a function. Got: ${ resolver } `
374378 )
375379 }
380+
381+ if ( config . connectionAcquisitionTimeout < config . connectionTimeout ) {
382+ log . warn (
383+ 'Configuration for "connectionAcquisitionTimeout" should be greater than ' +
384+ 'or equal to "connectionTimeout". Otherwise, the connection acquisition ' +
385+ 'timeout will take precedence for over the connection timeout in scenarios ' +
386+ 'where a new connection is created while it is acquired'
387+ )
388+ }
376389 return config
377390}
378391
@@ -396,6 +409,7 @@ function sanitizeConfig(config: any) {
396409 config . fetchSize ,
397410 DEFAULT_FETCH_SIZE
398411 )
412+ config . connectionTimeout = extractConnectionTimeout ( config )
399413}
400414
401415/**
@@ -431,6 +445,26 @@ function validateFetchSizeValue(
431445 }
432446}
433447
448+ /**
449+ * @private
450+ */
451+ function extractConnectionTimeout ( config : any ) : number | null {
452+ const configuredTimeout = parseInt ( config . connectionTimeout , 10 )
453+ if ( configuredTimeout === 0 ) {
454+ // timeout explicitly configured to 0
455+ return null
456+ } else if ( configuredTimeout && configuredTimeout < 0 ) {
457+ // timeout explicitly configured to a negative value
458+ return null
459+ } else if ( ! configuredTimeout ) {
460+ // timeout not configured, use default value
461+ return DEFAULT_CONNECTION_TIMEOUT_MILLIS
462+ } else {
463+ // timeout configured, use the provided value
464+ return configuredTimeout
465+ }
466+ }
467+
434468/**
435469 * @private
436470 * @returns {ConfiguredCustomResolver } new custom resolver that wraps the passed-in resolver function.
0 commit comments