Question

My app aim to scan a proxy list. When i have a dead proxy the error event is call but the callback or the end event is never call, why ?

    var file = e.dataTransfer.files[i].path;
    content = fs.readFileSync(file, "UTF-8");
    var lines = content.split("\n");
    var nb = 0;
    async.each(lines, function(line, callback) {

        var arr = line.split(":");
        http.get({host: arr[0], port: arr[1], path: "http://www.google.fr", agent: false}, function(res, req) {
            if(res.statusCode == 200){
                el.className = '';
                el.innerHTML = arr[0] + ':' + arr[1] + '\n';
                nb = nb+1;
            }
            callback();
        }).on('error', function(e) {
            console.error(arr[0] + ':' + arr[1]);
        }).on('end', function(e) {
            console.error('End event nerver load...');
        });   
    },function(){
        el.className = '';
        el.innerHTML = 'Scan terminé. ' + nb + ' Proxy fonctionnels';
    });
Was it helpful?

Solution

It looks like you're using the async library.

The iterator you passed to async.each requires that you call the callback regardless of whether there's an error or not. If you don't call the callback, async will assume that the operation is still running and will wait forever.

When you encounter an error, you should call the callback and pass the error as the first parameter.

So here's an example of what I mean. I've added callback(e); to your error event handler.

    }).on('error', function(e) {
        console.error(arr[0] + ':' + arr[1]);
        callback(e);
    }).on('end', function(e) {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top