mcavage / node-ssh-agent

Node.js client library for interacting with the OpenSSH Agent
MIT License
23 stars 9 forks source link

requests that timeout can invoke callback more than once #6

Closed davepacheco closed 9 years ago

davepacheco commented 9 years ago

We're seeing occasional errors with the node-manta clients where the program fails with "TypeError: not a buffer". The exception is very disconnected from the real problem, so I described the details in node-manta#228. The problem turned out to be that ssh-agent successfully connected, but only after the timeout had expired, and it ended up calling the user callback twice. First, the 'timeout' callback was fired and the user's callback was called, but then the 'connect' callback also fired. I fixed this by changing the socket.end() in the timeout callback to a socket.destroy(). With that, I found that we were still crashing. This time, the 'close' callback also called the user's callback. So I also added a "timedout" boolean using the existing pattern that was used there.

I've been running this in a loop for a while now without reproducing the problem.

davepacheco commented 9 years ago

I amended the commit in response to code review feedback (moved the assignment of "timedout" up).