Skip to content

agentkeepalive detecting ECONNRESET #25

Closed

Description

@fengmk2

from Aryeh Schechter email:

Hello,

We recently started using agentkeepalive to pool our connections to aws and have been experiencing ECONNRESETs. We are using version 2.0.2 which has the fix for issue #23, but we are still getting these errors.

Why are you not listening for 'error' on the socket and handling it similar to 'close'? This would allow for the ability to catch the ECONNRESETs and retry the request without the hassle of the requiring library to handle 'uncaughtException' and trying to figure out where it came from.

Thanks,
Aryeh Schechter
www.glide.me

Activity

  1. fengmk2 commented on May 11, 2015

    @fengmk2
    MemberAuthor

    But because you are not listening on 'error' the process will crash before 'close' will get emitted. I added a listener locally to lib/_http_agent.js on line 233 on 'error' and have caught it once and not crashed. Since it only happens sporadicly, I don't know how to reproduce it.

    The stack trace isn't very helpful:

    write ECONNRESET
    
       at exports._errnoException (util.js:746:11)
    
       at WriteWrap.afterWrite (net.js:775:14)
    
  2. fengmk2 commented on May 11, 2015

    @fengmk2
    MemberAuthor

    agentkeepalive don't handle socket error event.

  3. LarsEckart commented on Jul 23, 2015

    @LarsEckart

    Hello,

    I have the same use case, using agentkeepalive together with aws/dynamodb.
    node10, about 6500 requests per minute per server and all 4 servers/applications ran into this error and didn't continue working (but also didnt crash completely)

    events.js:72
            throw er; // Unhandled 'error' event
                  ^
    Error: read ECONNRESET
        at errnoException (net.js:905:11)
        at TCP.onread (net.js:559:19)

    is what I got from logs.

  4. christhorwarth commented on Jul 28, 2015

    @christhorwarth

    I was able to get around this by making the following changes:

    In _http_agent.js around line 260, add this listener to the socket:

    s.on('error', function(err) {
    self.emit('error', err);
    });

    Then in agent.js, I catch the error and log it (around line 70):

    self.on('error', function(err) {
    log && log.error('Socket err', err);
    });

  5. impomezia commented on Aug 2, 2015

    @impomezia

    Workaround without change the source code:

    var createSocket = Agent.prototype.createSocket;
    Agent.prototype.createSocket = function(req, options) {
      var socket = createSocket.call(this, req, options);
      socket.on('error', function(err) {
        this.closeSocketCount++;
      }.bind(this));
    
      return socket;
    };

    ECONNRESET can easily reproduce: just shutdown a server after successful client request.
    ECONNREFUSED just try connect to closed port.

  6. fengmk2 commented on Aug 3, 2015

    @fengmk2
    MemberAuthor

    I will add a default error listen to avoid Unhandled 'error' event throw.

  7. self-assigned this
    on Aug 3, 2015
  8. vvo commented on Aug 27, 2015

    @vvo

    Just to make it clear, you added a default error handler but errors will still bubble up at some point to the request object for example?

    I am not sure to understand when does this unhandled error was triggered. In which cases?

  9. vvo commented on Aug 27, 2015

    @vvo
  10. fengmk2 commented on Aug 27, 2015

    @fengmk2
    MemberAuthor

    the request object is not handle by this module.
    This agent only handle socket.

  11. vvo commented on Aug 27, 2015

    @vvo

    Ok sorry, so to be more precise, when was this unhandled error triggered?

    What were the possible unhandled errors, only ECONNRESET? Or was it possible to also get ETIMEDOUT or ENOTFOUND?

    I am asking because we got a support request on one of our libs using agentkeepalive and wondered if this was linked.

    I talked about request error event because in the end this is where we catch error when using agentkeepalive (because you forward them right?)

  12. fengmk2 commented on Aug 27, 2015

    @fengmk2
    MemberAuthor

    The error event is emitted by the socket and agentkeepalive won't block it.

    I think request object need to handle the error if the request object is an eventemitter.

  13. vvo commented on Aug 27, 2015

    @vvo

    I am trying to find a more detailed explanation of this issue, were you able to easily reproduce the error?

    Reading 24afa4a I cannot see a test case that is reproducing this behavior.

    To sump up: can you explain how from a user POV this error would happen.

    Using agentkeepalive for example and trying to make a request to an unknown hostname, I did get the error event (in 2.0.2). So I am not sure to understand the issue.

  14. fengmk2 commented on Mar 10, 2016

    @fengmk2
    MemberAuthor

    @vvo https://github.com/nodejs/node/pull/4482/files ide sockets will fire error event and no body will handle it.

  15. fengmk2 commented on Mar 10, 2016

    @fengmk2
    MemberAuthor

    Root cause is idle socket will emit error event.

    nodejs/node#4482

  16. vvo commented on Mar 10, 2016

    @vvo

    thanks for update

  17. added a commit that references this issue on Mar 12, 2016
    f588a95
  18. added a commit that references this issue on Jun 24, 2025
    24afa4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions