You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2020/11/09 08:32:24 UTC

[couchdb-nano] branch main updated: ensure only one HttpAgent is created (not one per request) - fixes issue #234 (#235)

This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git


The following commit(s) were added to refs/heads/main by this push:
     new 6131f56  ensure only one HttpAgent is created (not one per request) - fixes issue #234 (#235)
6131f56 is described below

commit 6131f56457e099576a4001a242309b6d7539c2a4
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Mon Nov 9 08:32:15 2020 +0000

    ensure only one HttpAgent is created (not one per request) - fixes issue #234 (#235)
    
    Co-authored-by: Glynn Bird <gl...@apache.org>
---
 lib/nano.js | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/nano.js b/lib/nano.js
index 14e61d3..3bd1d81 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -20,6 +20,8 @@ const http = require('http')
 const https = require('https')
 const pkg = require('../package.json')
 const AGENT_DEFAULTS = { keepAlive: true, maxSockets: 50, keepAliveMsecs: 30000 }
+const defaultHttpAgent = new http.Agent(AGENT_DEFAULTS)
+const defaultHttpsAgent = new https.Agent(AGENT_DEFAULTS)
 const ChangesReader = require('./changesreader.js')
 
 function isEmpty (val) {
@@ -331,8 +333,8 @@ module.exports = exports = function dbScope (cfg) {
     } else if (opts.dontParse) {
       req.responseType = 'arraybuffer'
     }
-    req.httpAgent = cfg.requestDefaults.agent || new http.Agent(AGENT_DEFAULTS)
-    req.httpsAgent = cfg.requestDefaults.agent || new https.Agent(AGENT_DEFAULTS)
+    req.httpAgent = cfg.requestDefaults.agent || defaultHttpAgent
+    req.httpsAgent = cfg.requestDefaults.agent || defaultHttpsAgent
 
     // actually do the HTTP request
     if (opts.stream) {