chill117 / proxy-verifier

NodeJS module to check proxies: if functional, anonymity level, tunneling, supported protocols.
MIT License
76 stars 16 forks source link

Error: Callback was already called. #13

Closed cyclops24 closed 8 years ago

cyclops24 commented 8 years ago

Hi @chill117, I used this code and sometimes it's return below error and app server restarted at all:

W20160729-19:02:08.443(4.5)? (STDERR) /home/usename/Projects/Proxy Assistant/Sources/node_modules/proxy-verifier/node_modules/async/lib/async.js:43
W20160729-19:02:08.444(4.5)? (STDERR)             if (fn === null) throw new Error("Callback was already called.");
W20160729-19:02:08.444(4.5)? (STDERR)                              ^
W20160729-19:02:08.445(4.5)? (STDERR) 
W20160729-19:02:08.446(4.5)? (STDERR) Error: Callback was already called.
W20160729-19:02:08.446(4.5)? (STDERR)     at /home/usename/Projects/Proxy Assistant/Sources/node_modules/proxy-verifier/node_modules/async/lib/async.js:43:36
W20160729-19:02:08.446(4.5)? (STDERR)     at /home/usename/Projects/Proxy Assistant/Sources/node_modules/proxy-verifier/node_modules/async/lib/async.js:723:17
W20160729-19:02:08.446(4.5)? (STDERR)     at /home/usename/Projects/Proxy Assistant/Sources/node_modules/proxy-verifier/node_modules/async/lib/async.js:167:37
W20160729-19:02:08.447(4.5)? (STDERR)     at /home/usename/Projects/Proxy Assistant/Sources/node_modules/proxy-verifier/index.js:248:4
W20160729-19:02:08.447(4.5)? (STDERR)     at Request.<anonymous> (/home/usename/Projects/Proxy Assistant/Sources/node_modules/proxy-verifier/index.js:445:4)
W20160729-19:02:08.447(4.5)? (STDERR)     at emitOne (events.js:77:13)
W20160729-19:02:08.447(4.5)? (STDERR)     at Request.emit (events.js:169:7)
W20160729-19:02:08.448(4.5)? (STDERR)     at Request.onRequestError (/home/usename/Projects/Proxy Assistant/Sources/node_modules/proxy-verifier/node_modules/request/request.js:820:8)
W20160729-19:02:08.448(4.5)? (STDERR)     at emitOne (events.js:77:13)
W20160729-19:02:08.448(4.5)? (STDERR)     at ClientRequest.emit (events.js:169:7)
=> Exited with code: 1

This is my code:

            // proxy format: http://192.168.1.1:8080 (Protocol://IP:PORT)
            let proxyParts = proxy.proxy.split(":");
            let protocol = proxyParts[0].toLowerCase();
            let ipAddress = proxyParts[1].replace("//", "");
            let port = proxyParts[2];

            let proxyObj = {
                ipAddress: ipAddress,
                port: port,
                protocol: protocol
            };
            ProxyVerifier.testAll(proxyObj, Meteor.bindEnvironment((error, result) => {

                if (error) {
                    // Some unusual error occurred.
                } else {
                    // anonymityLevel will be a string equal to "transparent", "anonymous", or "elite".
                    if (result.anonymityLevel === "elite" && result.protocols[proxyObj.protocol].ok) {
                        Proxies.update({_id: proxy._id}, {$inc: {point: 1}});
                    } else {
                        Proxies.update({_id: proxy._id}, {$inc: {point: -1}});
                    }
                }
            }));

Do you have any suggestion?? My code is wrong or it's a bug?

chill117 commented 8 years ago

That is probably a bug.

cyclops24 commented 8 years ago

@chill117 Thanks man for rapidly comment. :smile: You are awesome. :wink:

cyclops24 commented 8 years ago

@chill117 Maybe it's about testAll function, because I used testProtocol before without any issue with same proxy list. For example this code works fine without any issue:

ProxyVerifier.testProtocol(proxyObj, Meteor.bindEnvironment((error, result) => {

                if (error) {
                    // Some unusual error occurred.
                } else {
                    if (result.ok) {
                        Proxies.update({_id: proxy._id}, {$inc: {point: 1}});
                    } else {
                        Proxies.update({_id: proxy._id}, {$inc: {point: -1}});
                    }
                }
            }));
chill117 commented 8 years ago

Yes, that is most likely. I was working on some improvements (mostly with stability) for testAll and other functions. But I haven't had a chance to finish the changes yet.

cyclops24 commented 8 years ago

So I wait for new release man. :wink:

cyclops24 commented 8 years ago

@chill117 I convert my code to below and again same error accord:

ProxyVerifier.testProtocol(proxyObj, Meteor.bindEnvironment((error, result) => {

                if (error) {
                    // Some unusual error occurred.
                } else {
                    if (result.ok) {
                        ProxyVerifier.testAnonymityLevel(proxyObj, Meteor.bindEnvironment((error, anonymityLevel) => {

                            if (error) {
                                // Some unusual error occurred.
                            } else {
                                // anonymityLevel will be a string equal to "transparent", "anonymous", or "elite".
                                if (anonymityLevel === "elite") {
                                    Proxies.update({_id: proxy._id}, {$inc: {point: 1}});
                                } else {
                                    Proxies.update({_id: proxy._id}, {$inc: {point: -1}});
                                }
                            }
                        }));
                    }
                    else {
                        Proxies.update({_id: proxy._id}, {$inc: {point: -1}});
                    }
                }
            }));

I guess this issue also related to testAnonymityLevel function too.

cyclops24 commented 8 years ago

@chill117 when you want to fix this or push your past changes?

chill117 commented 8 years ago

Not sure when I will have time for this. Could be a week or so.

cyclops24 commented 8 years ago

Thanks man so I can wait for it :wink:

snajjar commented 8 years ago

+1, same problem here.

Kladdkaka commented 8 years ago

+1 same problem here, this is my code:

const ProxyLists = require('proxy-lists');
const ProxyVerifier = require('proxy-verifier');

// `gettingProxies` is an event emitter object.
var gettingProxies = ProxyLists.getProxies();

var proxies = [];

function pushItemsToArray(data_array, target_array) {
    data_array.forEach(function (item) {
        target_array.push(item);
    });
}

function checkProxies(proxies) {
    proxies.forEach(function (proxy) {
        ProxyVerifier.testAll(proxy, function (error, result) {

            if (error) {
                console.log(error);
            } else {
                console.log(result);
            }

        });
    });
}

gettingProxies.on('data', function (raw_proxies) {
    // Received some proxies.
    console.log("aye");
    pushItemsToArray(raw_proxies, proxies);
});

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

gettingProxies.once('end', function () {
    // Done getting proxies.
    checkProxies(proxies);
});

thanks for a amazing library by the way! 👍 :)

chill117 commented 8 years ago

This issue has been fixed upstream in the proxy-lists module.