Search code examples
javascriptnode.jsmeteornpmeventemitter

Error: ETIMEDOUT on NPM usage in Meteor


I try to use this NPM packages in Meteor 1.3.2.4. It use eventemitter in functions and has asyncronous callbacks. I try to convert it to synchronous-looking with Meteor.bindEnvironment based on this guide article like below:

Meteor.methods({
    proxyFetcher() {
        console.log("OK run");
        var options = {
            protocols: ['http'],
            anonymityLevels: ['elite'],
            sourcesBlackList: ['bitproxies', 'kingproxies']
        };

    var gettingProxies = ProxyLists.getProxies(options);
    Proxies.remove({});

    gettingProxies.on('data', Meteor.bindEnvironment(function(proxies) {
        console.log(proxies.length);
        proxies.forEach((proxy) => {
            Proxies.insert({proxy: proxy.ipAddress + ":" + proxy.port});
        });
        // Received some proxies.
    }));
}
}

but it is my output:

I20160515-12:08:02.579(4.5)? OK run
I20160515-12:08:03.250(4.5)? 44
I20160515-12:08:03.645(4.5)? 29
I20160515-12:08:03.963(4.5)? 35
I20160515-12:08:04.376(4.5)? 349
I20160515-12:08:04.711(4.5)? 337
I20160515-12:08:05.071(4.5)? 350
I20160515-12:08:05.853(4.5)? 330
I20160515-12:08:06.149(4.5)? 323
I20160515-12:08:06.443(4.5)? 331
I20160515-12:08:06.737(4.5)? 324
I20160515-12:08:07.039(4.5)? 334
W20160515-12:08:08.083(4.5)? (STDERR) 
W20160515-12:08:08.084(4.5)? (STDERR) Error: ETIMEDOUT
W20160515-12:08:08.085(4.5)? (STDERR)     at [object Object]._onTimeout (/home/cyc/Programming/Projects/proxyCheck/Sources/node_modules/proxy-lists/node_modules/request/request.js:762:15)
W20160515-12:08:08.085(4.5)? (STDERR)     at Timer.listOnTimeout [as ontimeout] (timers.js:121:15)
=> Exited with code: 8
=> Meteor server restarted

As you seen server restarted and my code return error after some iteration. What is the problem and what is the right way to use this package with Meteor.


Solution

  • Presumably one of the http requests made by proxy-lists is failing, and this error uncaught, so it is bubbling up to crash the entire Node process.

    If you handle the error, that should prevent it from crashing the process:

    gettingProxies.on('error', function(error) {
        // Some error has occurred.
        console.error(error);
    });