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

Uncaught TypeError when using keep-alive HTTP agent #1137

Closed
cdhowie opened this issue Sep 14, 2016 · 6 comments
Closed

Uncaught TypeError when using keep-alive HTTP agent #1137

cdhowie opened this issue Sep 14, 2016 · 6 comments
Labels
guidance Question that needs advice or information.

Comments

@cdhowie
Copy link

cdhowie commented Sep 14, 2016

By simply adding this code to our application:

AWS.config.update({
    httpOptions: {
        agent: new http.Agent({ keepAlive: true })
    }
});

The following exception is thrown some time later, after numerous successful operations:

     Uncaught TypeError: cb is not a function
      at afterWrite (_stream_writable.js:354:3)
      at onwrite (_stream_writable.js:345:7)
      at WritableState.onwrite (_stream_writable.js:89:5)
      at Socket._writeGeneric (net.js:706:5)
      at Socket._writev (net.js:711:8)
      at doWrite (_stream_writable.js:298:12)
      at clearBuffer (_stream_writable.js:387:5)
      at Socket.Writable.uncork (_stream_writable.js:237:7)
      at ClientRequest._flushOutput (_http_outgoing.js:673:10)
      at ClientRequest.OutgoingMessage._flush (_http_outgoing.js:647:16)
      at _http_client.js:156:10
      at callSocketMethod (_http_client.js:552:7)
      at ClientRequest.onSocket (_http_client.js:557:7)
      at tickOnSocket (_http_client.js:523:7)
      at onSocketNT (_http_client.js:535:5)

Changing keepAlive to false eliminates the errors.

Node 4.5.0 and aws-sdk 2.6.2.

@chrisradek
Copy link
Contributor

@cdhowie
Are you making calls across multiple services? Do you know if it's a specific operation that always throws the exception? How long is 'some time later'?

@cdhowie
Copy link
Author

cdhowie commented Sep 15, 2016

These service tests exclusively run against DynamoDB. At the point where it fails, there are multiple concurrent requests and they are all DeleteItem requests. It will consistently fail on that test, and I haven't been able to locate any bug in my code (yet).

It probably makes it through 50 or so requests before failing, and I know that some of the other tests involve concurrent deletions. Everything works fine until I enable keepalive.

@cdhowie
Copy link
Author

cdhowie commented Sep 15, 2016

My spidey sense says this is actually a bug in Node's http.Agent class, but I'm not super-familiar with Node's internals so I'm not well-equipped to go about debugging them to make sure. So I'm not sure if I should leave this issue open or go report it to Node. :/

The first stack frame shown is this Node-internal code:

function afterWrite(stream, state, finished, cb) {
  if (!finished)
    onwriteDrain(stream, state);
  state.pendingcb--;
  cb();
  finishMaybe(stream, state);
}

The cb() invocation is what's failing. This parameter gets set earlier from state.writecb, which, according to the comments in that file, are supplied when invoking write() on the stream. Apparently the callback is required, at least in Node v4? That doesn't match the docs, but it wouldn't be the first time the docs are wrong.

@cdhowie
Copy link
Author

cdhowie commented Sep 18, 2016

I am seeing the same behavior on Node 6.6.0 using the stock http.Agent with keepAlive: true.

@chrisradek
Copy link
Contributor

Closing old issues. Please open a new issue if you are still encountering this behavior.

@srchase srchase added guidance Question that needs advice or information. and removed Question labels Jan 4, 2019
@lock
Copy link

lock bot commented Sep 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

3 participants