添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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
  • OS : win32
  • Scope (install, code, runtime, meta, other?) : code
  • Module (and version) (if relevant) : https
  • I use https.request to read from server, and the response is fine. But after several minutes, ECONNRESET error crash the application. My question is, besides process.on('uncaughtException') (not recommended by Nodejs), is there a proper way to catch and handle ECONNRESET for https.request?

    { Error: read ECONNRESET at exports._errnoException (util.js:1050:11) at TCP.onread (net.js:582:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

    Below is my code.
    ` var options = {
    method: 'GET',
    hostname: hostname,
    path: url,
    auth: username + ':' + password,
    ca: [fs.readFileSync(path.resolve(__dirname, '../common/cer.cer'))],

    const req = https.request(options, function (res) {
      res.on('data', (resdata) => {
        console.log('data');
      res.on('end', () => {
        console.log('end');
    req.on('error', (e) => {
      console.log(e);
    req.end();
              

    @bnoordhuis
    Thanks for the reply. But sadly req.on('error', ...) doesn't get triggered. The request is fine and get correct resonse from server . The ECONNRESET happened several minutes later, so I guess by then the request is over and its event can't be triggered. Possibly I'm facing similar problems as nodejs/node#3595

    BTW, I tried using with or without keep-alive agent, and even listened socket event 'error'/'close' when req.on('socket') and did socket.close() and socket.emit('agentRemove'). But none of this helps, the error occured over and over again.

    Please suggest.

    @bnoordhuis
    I see this issue in docker(Linux) with Node 6.x and my local Windows 7 with Node 7.10.
    I'll try Node 8 and let you know the result.

    @bnoordhuis I tried NodeJS 8, and got error again.
    current time: 22:51:2.750 http.request complete
    current time: 23:6:1.770 Error: read ECONNRESET
    C:\nodejs>node -v
    v8.1.3

    I'm experiencing something similar (see my comment in this issue). This may also be related to this issue. I've posted code that reproduces the error (albeit, after a 5 or 10 minute wait) in the linked comment above.

    Edit: Oh, just realised that this isn't the request repo! I think the issue may have the same source in any case.

    I used this block of code and for now it seems to work,

    process.on('uncaughtException', (err) => console.log('node js process error\n', err));
    const server = require('http2').createSecureServer(options, (req, res) => {
        // my codes...
    server.on('clientError', (err, socket) => {
        if (err.code === 'ECONNRESET' || !socket.writable) socket.end('HTTP/2 400 Bad Request\n');
        console.log('client error\n', err);
    server.listen(PORT, (err) => (!err) ? console.log('listening on port', PORT) : console.log('something went wrong\n', err));
              

    ashtro-0 you're a life saver.
    I just used the server.on lump and it caught the exception which originated in the node process I was trying to talk to
    Cheers.