1

I am trying to get couchbase document revision identifier via sync gatetway API GET /{db}/{doc} within Node server:

function _getRev(docIdUrl, gateway, callback) {

    let options = {
        host: gateway.host,
        path: gateway.path + docIdUrl,
        port: gateway.port,
        method: 'GET',
        headers: {
            'Content-Type': 'application/json'
        }
    };

    // Node HTTP requests
    let syncGatewayRequest = http.request(options, (response) => {
           // ...unrelevant codes
    });

    syncGatewayRequest.on('error', (error) => {
        logger.error('syncGateway connection error for ' + docIdUrl);
        callback(error, null); // here is the error happening!!!!!
    });

    syncGatewayRequest.write(JSON.stringify({}));
    syncGatewayRequest.end();
}

Then I got error:

[2017-11-03 11:07:51.961] { [Error: connect EMFILE 10.0.1.53:4985 - Local (undefined:undefined)]
  code: 'EMFILE',
  errno: 'EMFILE',
  syscall: 'connect',
  address: '10.0.1.53',
  port: 4985 }
Error: connect EMFILE 10.0.1.53:4985 - Local (undefined:undefined)
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at connect (net.js:849:16)
    at net.js:937:9
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickCallback (node.js:349:13)

There is a context that the above function are executed asynchronously by a significant number of services, say 10,000+

I noticed the post here Nodejs connect EMFILE - How to reuse connections?

But I tried to unlimit the default connections by doing:

var http = require('http')
http.globalAgent.maxSockets = Infinity

But does not seem to work, error still ...

Anyone can let me know what's wrong here?

leonsPAPA
  • 657
  • 2
  • 13
  • 29
  • Possible duplicate of ["connect EMFILE" error in Node.js](https://stackoverflow.com/questions/10355501/connect-emfile-error-in-node-js) – Veve Sep 17 '19 at 09:28

0 Answers0