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

unhandled exception ECONNRESET, when using proxy #313

Open
jerradpatch opened this issue Apr 30, 2019 · 2 comments
Open

unhandled exception ECONNRESET, when using proxy #313

jerradpatch opened this issue Apr 30, 2019 · 2 comments

Comments

@jerradpatch
Copy link

I am having this annoying issue while using http proxies. The exception happens in the global context and doesn't leave much of a stack trace.

Error: read ECONNRESET
at _errnoException (util.js:1024:11)
at TCP.onread (net.js:615:25)

which can only be caught using the "process.on('uncaughtException', ...)" event.

If I remove the proxies then no uncaught exceptions are thrown. I have looked at the related issues but I have yet to find anything that allows me to catch the exception on the request:

"request/request#3131"
"request/request#2986"
"request/request#2846"

I am calling the request like this:

process.on('uncaughtException', function (err) {
        debugger;
        console.log(err); //exception can only be caught here
      });

for (let i = 0; i < 2000; ++i) {
          let userAStr = random_useragent.getRandom();
          let req = npl.request({
            gzip: true,
            method: 'GET',
            uri: 'https://nyaa.si/view/1116270',
            timeout: 30 * 1000,
            maxRedirects: '10',
            followRedirect: true,
            rejectUnauthorized: false,
            insecure: true,
            headers: {
              'user-agent': userAStr
            }
          }).catch(e => {
            if (e.statusCode !== 404)
              debugger;
          });

          allTests.push(req);
        }

        Promise.all(allTests).then(all => {
          debugger;
        })

and here is the request code, as you can see I have tried a lot of things to try and catch this exception.

 private reqProm(ops){
    return new Promise((c, e)=>{
      let prom;

      let handle = setTimeout(()=> {
        prom && prom['cancel'] && prom['cancel']();
        e({
          error: {
            code: 'ESOCKETTIMEDOUT'
          }})
      }, this['timeout']);

      try {
        ops.gzip = true;
        if(!ops.headers)
          ops.headers = {};
        ops.headers.Connection = 'keep-alive';
        console.log("trying", ops);
        let rr = rp(ops)
          .on('error', err => {
            console.log('got in error event', err.message);
            clearTimeout(handle);
            e({error:err});
          })
          .on('socket', sock => {
            sock.on('error', err => {
              console.log('got in sock error event', err.message);
              clearTimeout(handle);
              e({error:err});
            })
          })
        rr.then((res) => {
          clearTimeout(handle);
          c(res);
        }).catch(err => {
          clearTimeout(handle);
          e(err);
        });
        rr.end();
      } catch (err) {
        clearTimeout(handle);
        e(err);
      }
    })
  }

The issue doesn't happen all the time, in fact, it takes many request before it occurs. The code is part of a github library that I am trying to create.
"https://github.com/jerradpatch/node-proxy-pools"

It currently needs a key for a proxy api called "Proxy Rotator". If the problem isnt obvious, you need to run the code, and you would like to borrow my key in order to help me figure it out. I would be willing to give the key to any active contributor of the request-promise library. Thanks so much for your help.

@sahilarorafzr
Copy link

I have noticed the same with proxy being used on production system.

@milad2golnia
Copy link

I'm facing same error when using some proxies here.
But some of them are behaving correctly.

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

3 participants