Sync gateway connection Error: connect EMFILE - Local (undefined:undefined) - node.js

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?

Related

Can't make a POST request on Azure - EACCES

I have a Node application hosted in Azure as a Web App Bot. When I try to make a POST request with axios from that application, it gives me the following error:
{ Error: connect EACCES 172.30..etc etc
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
errno: 'EACCES',
code: 'EACCES',
syscall: 'connect',
address: '172.30..etc,etc',
port: 443,
config:
...
Locally, testing with Bot Framework Emulator it works like a charm.
Request:
let reqConfig = {
headers: {
"Authorization": '123etc etc',
"Content-Type": "application/json"
}
}
axios.post("https://_______", body, reqConfig).then(r => {
console.log(r);
}).catch(e => {
console.log('ERR: ', e);
})

How to fire POST request using inline editor in dialogflow?

Code:
var rp = require('request-promise');
var options = {
method: 'POST',
uri: 'http://c663fe13.ngrok.io/ap/lighton',
body: {"color": 'white'},
json: true // Automatically stringifies the body to JSON
};
rp(options)
.then(function (parsedBody) {
// POST succeeded...+
console.log("parsedBody", parsedBody);
})
.catch(function (err) {
// POST failed...
console.log("err", err);
});
but this gives me the following error:
{ RequestError: Error: getaddrinfo EAI_AGAIN c663fe13.ngrok.io:80
at new RequestError (/srv/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/srv/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/srv/node_modules/request-promise-core/lib/plumbing.js:46:31)
. . .
name: 'RequestError', message: 'Error: getaddrinfo EAI_AGAIN
c663fe13.ngrok.io:80',
cause: { Error: getaddrinfo EAI_AGAIN
c663fe13.ngrok.io:80
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
errno: 'EAI_AGAIN',
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'c663fe13.ngrok.io',
host: 'c663fe13.ngrok.io',
port: 80 },
I trie to call that API with postman and it's working fine.
If you are using a free account you will not be able to hit any 3rd party services from Firebase cloud functions. It would be better if you write down your own webhook code and using fulfillment integrate that webhook with your Dialogflow agent if you are going to use the free account.
UPDATE
Check out the code snippets I have shared here. You can use that to integrate ExpressJS and then add your POST code and host it locally. Expose the local server using ngrok and then put that URL in fulfillment.

node js won't let me use proxies

I'm trying to use the request-module to scrape websites and get the response-HTML. To prevent getting blocked by the target sites I need to use some proxies. But for some reason I can not accomplish to use request with a proxy.
I've also tried many different proxies and none of them will do the job.
My code:
const request = require('request');
const cheerio = require('cheerio');
var servers = [
'http://173.249.48.240:8080',
'http://85.214.250.48:3128'
]
var options = {
'url': 'http://www.google.de',
'proxy': servers[1]
};
request(options, (err,res,body) => {
console.log(res);
console.log(body);
console.log(err);
try {
var $ = cheerio.load(body);
console.log($('#ipv4').html());
} catch(err) {
//do nothing
}
})
I've tried many different proxies and have also used nightmare before but everytime I try to connect with a Proxy I get the following exception:
{ Error: connect ECONNREFUSED 85.214.250.48:3128
at Object._errnoException (util.js:1024:11)
at _exceptionWithHostPort (util.js:1046:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '85.214.250.48',
port: 3128 }

Node.js Error : connect ECONN Refused

I am new to Node.js and am unable to resolve this error:
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect (as oncomplete) (net.js:892)
The code I was trying out follows :
var async = require('async'),
request = require('request');
function done(err,results) {
if (err) {
throw err;
}
console.log('Done ! results: %j',results);
}
var collection = [1,2,3,4];
function iterator(value,callback) {
request.post({
url: 'http://localhost:8080',
body: JSON.stringify(value)
}, function (err,res,body){
if (err) {
callback(err,body && JSON.parse(body));
}
});
}
async.map(collection,iterator,done);
ECONNREFUSED – Connection refused by server error
A port is being blocked can be the root cause of this issue, check if your connection is being blocked or even the changed default port can also cause this issue. Identify which app/service you are connecting to and its port is being blocked or changed.
And in your case check whether the application is hosted on port: 8080 or not.
But, this most likely occurs with FileZilla.

Getting error while using http in node.js

Below is the error getting while calling http get request
events.js:66
throw arguments[1]; // Unhandled 'error' event
^
Error: getaddrinfo ENOENT
at errnoException (dns.js:31:11)
at Object.onanswer [as oncomplete] (dns.js:123:16)
PFB my code throwing the error
var options = {
host: 'http://xyz.com',
port: 80,
path : 'test?query=' + escape(req.params.searchTerm) + '&offset=0&hits=500',
method: 'GET',
headers: {
Cookie : "session=" + session
}
};
console.log("Start");
var x = http.request(options,function(subRes){
console.log("Connected");
subRes.on('data',function(data){
console.log("===================data===" +util.inspect(data));
});
});
x.end();
Any ideas, why this error ?
ENOENT is an error that indications name resolution did not return any results. You specify the hostname as http://xyz.com, but colons are not allowed in hostnames. You want:
var options = {
host: 'xyz.com',
You specify the host as http://xyz.com, which should just be xyz.com.
This value is used to resolve the IP address of the host you're trying to connect to using DNS.

Resources