socks5-https-client icon indicating copy to clipboard operation
socks5-https-client copied to clipboard

Error: getaddrinfo EMFILE localhost:9050

Open alparslanahmed opened this issue 8 years ago • 3 comments

I have a request inside loop. After starting my program it gives this error:

Error: getaddrinfo EMFILE localhost:9050

Is there any option for close socket after request?

alparslanahmed avatar Dec 18 '16 07:12 alparslanahmed

Hi @alparslanahmed, I'm not sure I understand. Have you tried calling #close() on the request object?

mattcg avatar Dec 18 '16 11:12 mattcg

Hi @mattcg, here its the code above. I am executing this method every 500ms.

static events() {
        const userAgentString = userAgentGenerator();

        request({
            url: listUrl,
            agentClass: Agent,
            agentOptions: {
                socksHost: 'localhost',
                socksPort: 9050
            },
            headers: {
                'User-Agent': userAgentString
            },
            forever: true,
            pool: { maxSockets: Infinity }
        }, function (err, res) {
            if (err) {
                console.error('Error when requesting events list: ', err);
            } else if (!res) {
                console.log('Null response when requesting events list: ', res);
            } else {
                Service.parseEvents(res.body);
            }
        });

    }

And this is console output for every request:


 Error when requesting events list:  { Error: getaddrinfo EMFILE localhost:9050
 at Object.exports._errnoException (util.js:1036:11) 
 at errnoException (dns.js:33:15)
 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'EMFILE',
errno: 'EMFILE',
syscall: 'getaddrinfo',
hostname: 'localhost',
host: 'localhost',
port: 9050 }

alparslanahmed avatar Dec 19 '16 16:12 alparslanahmed

@alparslanahmed the error means that your system is denying Node.js permission to open more sockets. It could be that in your loop you aren't waiting for the request to complete before the next iteration and are therefore flooding your system with connections.

mattcg avatar Jun 21 '17 10:06 mattcg