@@ -432,10 +432,16 @@ export type Config = {
432432 * module when using arangojs in the browser). This will be ignored if
433433 * `agent` is also provided.
434434 *
435- * The option `maxSockets` can also be used to limit how many requests
435+ * The option `maxSockets` is also used to limit how many requests
436436 * arangojs will perform concurrently. The maximum number of requests is
437- * equal to `maxSockets * 2` with `keepAlive: true` or equal to `maxSockets`
438- * with `keepAlive: false` (or in the browser).
437+ * equal to `maxSockets`.
438+ *
439+ * **Note:** arangojs will limit the number of concurrent requests based on
440+ * this value even if an `agent` is provided.
441+ *
442+ * **Note:** when using `ROUND_ROBIN` load balancing and passing an array of
443+ * URLs in the `url` option, the default value of `maxSockets` will be set
444+ * to `3 * url.length` instead of `3`.
439445 *
440446 * Default (Node.js): `{ maxSockets: 3, keepAlive: true, keepAliveMsecs: 1000 }`
441447 *
@@ -509,40 +515,41 @@ export class Connection {
509515 * @hidden
510516 */
511517 constructor ( config : Omit < Config , "databaseName" > = { } ) {
518+ const URLS = config . url
519+ ? Array . isArray ( config . url )
520+ ? config . url
521+ : [ config . url ]
522+ : [ "http://localhost:8529" ] ;
523+ const MAX_SOCKETS =
524+ 3 * ( config . loadBalancingStrategy === "ROUND_ROBIN" ? URLS . length : 1 ) ;
525+
512526 if ( config . arangoVersion !== undefined ) {
513527 this . _arangoVersion = config . arangoVersion ;
514528 }
515529 this . _agent = config . agent ;
516530 this . _agentOptions = isBrowser
517- ? { maxSockets : 3 , ...config . agentOptions }
531+ ? { maxSockets : MAX_SOCKETS , ...config . agentOptions }
518532 : {
519- maxSockets : 3 ,
533+ maxSockets : MAX_SOCKETS ,
520534 keepAlive : true ,
521535 keepAliveMsecs : 1000 ,
522536 scheduling : "lifo" ,
523537 ...config . agentOptions ,
524538 } ;
525539 this . _maxTasks = this . _agentOptions . maxSockets ;
526- if ( this . _agentOptions . keepAlive ) this . _maxTasks *= 2 ;
527-
528540 this . _headers = { ...config . headers } ;
529- this . _loadBalancingStrategy = config . loadBalancingStrategy || "NONE" ;
541+ this . _loadBalancingStrategy = config . loadBalancingStrategy ?? "NONE" ;
530542 this . _useFailOver = this . _loadBalancingStrategy !== "ROUND_ROBIN" ;
531543 this . _precaptureStackTraces = Boolean ( config . precaptureStackTraces ) ;
532544 if ( config . maxRetries === false ) {
533545 this . _shouldRetry = false ;
534546 this . _maxRetries = 0 ;
535547 } else {
536548 this . _shouldRetry = true ;
537- this . _maxRetries = config . maxRetries || 0 ;
549+ this . _maxRetries = config . maxRetries ?? 0 ;
538550 }
539551
540- const urls = config . url
541- ? Array . isArray ( config . url )
542- ? config . url
543- : [ config . url ]
544- : [ "http://localhost:8529" ] ;
545- this . addToHostList ( urls ) ;
552+ this . addToHostList ( URLS ) ;
546553
547554 if ( config . auth ) {
548555 if ( isBearerAuth ( config . auth ) ) {
0 commit comments