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

Caught exception: Error: read ECONNRESET #1564

Closed
zdying opened this issue Oct 19, 2018 · 8 comments
Closed

Caught exception: Error: read ECONNRESET #1564

zdying opened this issue Oct 19, 2018 · 8 comments

Comments

@zdying
Copy link

zdying commented Oct 19, 2018

  • Node.js Version: v10.9.0
  • OS: MacOS
  • Scope: runtime

hi, i have an Node.js app that will use http.request and https.request. some times it print some log:

Caught exception:  Error: read ECONNRESET
    at TCP.onread (net.js:660:25)

but no detail error stack printed. so i don't know where the error has been emitted and which domain request failed.

I want to catch the error myself and get the full error.stack , what can i do?

@gireeshpunathil
Copy link
Member

have you installed an error handler on the request object? such as:

request.on('error', (e) => {
   console.log(e)
})

and does it improve the situation any better?

@gireeshpunathil
Copy link
Member

ping @zdying

@zdying
Copy link
Author

zdying commented Jun 13, 2019

Yes, i have error handler. my code is:

proxy.on('error', function (e) {
    if (e.code === 'ENOTFOUND') {
      res.statusCode = 404;
    } else {
      res.statusCode = 500;
    }
    res.end(e.stack);
    next();
});

I think if not add error handler, it will throw UncaughtException, NOT Caught exception.

@gireeshpunathil
Copy link
Member

@zdying - I did not follow your last statement, can you please clarify?

@gireeshpunathil
Copy link
Member

ping @zdying

@zdying
Copy link
Author

zdying commented Oct 30, 2019

I mean that I Have error handler. I think If no error handler provided, it SHOULD tell me I have an uncaught error, and should NOT tell me it’s a caught error.

I don’t know what does the “caught exception” mean

@gireeshpunathil
Copy link
Member

probably related: nodejs/node#14102

@zdying - without a program to reproduce the issue it is really difficult to pin point the root cause. At high level, the module that issues the request (plain tcp socket / http request api / request module or any other middleware component) should install an error handler, which gets invoked on a low level event such as network read error. In your case, I would recommend:

  • figure out which object is issuing the network request
  • install an error handler and see if it catches the error
  • if not, identify the network primitive that the module / object is abstracting
  • install an error handler for that and see if it catches at that point
  • iterate this approach until you get the callback or find the root cause

@zdying
Copy link
Author

zdying commented Nov 11, 2019

@gireeshpunathil OK, i will try it. thanks.

@zdying zdying closed this as completed Nov 11, 2019
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

2 participants