@@ -26,6 +26,7 @@ import {
26
26
ACCESS_MODE_READ ,
27
27
ACCESS_MODE_WRITE ,
28
28
FETCH_ALL ,
29
+ DEFAULT_CONNECTION_TIMEOUT_MILLIS ,
29
30
DEFAULT_POOL_ACQUISITION_TIMEOUT ,
30
31
DEFAULT_POOL_MAX_SIZE
31
32
} from './internal/constants'
@@ -131,12 +132,15 @@ class Driver {
131
132
createSession : CreateSession = args => new Session ( args )
132
133
) {
133
134
sanitizeConfig ( config )
134
- validateConfig ( config )
135
+
136
+ const log = Logger . create ( config )
137
+
138
+ validateConfig ( config , log )
135
139
136
140
this . _id = idGenerator ++
137
141
this . _meta = meta
138
142
this . _config = config
139
- this . _log = Logger . create ( config )
143
+ this . _log = log ;
140
144
this . _createConnectionProvider = createConnectonProvider
141
145
this . _createSession = createSession
142
146
@@ -366,13 +370,22 @@ class Driver {
366
370
* @private
367
371
* @returns {Object } the given config.
368
372
*/
369
- function validateConfig ( config : any ) : any {
373
+ function validateConfig ( config : any , log : Logger ) : any {
370
374
const resolver = config . resolver
371
375
if ( resolver && typeof resolver !== 'function' ) {
372
376
throw new TypeError (
373
377
`Configured resolver should be a function. Got: ${ resolver } `
374
378
)
375
379
}
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
+ }
376
389
return config
377
390
}
378
391
@@ -396,6 +409,7 @@ function sanitizeConfig(config: any) {
396
409
config . fetchSize ,
397
410
DEFAULT_FETCH_SIZE
398
411
)
412
+ config . connectionTimeout = extractConnectionTimeout ( config )
399
413
}
400
414
401
415
/**
@@ -431,6 +445,26 @@ function validateFetchSizeValue(
431
445
}
432
446
}
433
447
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
+
434
468
/**
435
469
* @private
436
470
* @returns {ConfiguredCustomResolver } new custom resolver that wraps the passed-in resolver function.
0 commit comments