Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: getaddrinfo EMFILE localhost:9050 #16

Open
alparslanahmed opened this issue Dec 18, 2016 · 3 comments
Open

Error: getaddrinfo EMFILE localhost:9050 #16

alparslanahmed opened this issue Dec 18, 2016 · 3 comments

Comments

@alparslanahmed
Copy link

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?

@mattcg
Copy link
Owner

mattcg commented Dec 18, 2016

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

@alparslanahmed
Copy link
Author

alparslanahmed commented Dec 19, 2016

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 }

@mattcg
Copy link
Owner

mattcg commented Jun 21, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants