Error: ETIMEDOUT on NPM usage in Meteor
Error: ETIMEDOUT on NPM usage in Meteor
我尝试像下面这样使用 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:
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.
}));
}
}
但这是我的输出:
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
如您所见,服务器重新启动,我的代码 return 经过一些迭代后出现错误。
问题是什么以及将这个包与 Meteor 一起使用的正确方法是什么。
大概是 proxy-lists 发出的一个 http 请求失败了,并且这个错误没有被捕获,所以它冒泡导致整个 Node 进程崩溃。
如果您处理错误,应该可以防止它导致进程崩溃:
gettingProxies.on('error', function(error) {
// Some error has occurred.
console.error(error);
});
我尝试像下面这样使用 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:
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.
}));
}
}
但这是我的输出:
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
如您所见,服务器重新启动,我的代码 return 经过一些迭代后出现错误。 问题是什么以及将这个包与 Meteor 一起使用的正确方法是什么。
大概是 proxy-lists 发出的一个 http 请求失败了,并且这个错误没有被捕获,所以它冒泡导致整个 Node 进程崩溃。
如果您处理错误,应该可以防止它导致进程崩溃:
gettingProxies.on('error', function(error) {
// Some error has occurred.
console.error(error);
});