joyent/node — Issue #2549: Double 'error' Events on HTTPS Requests
Author: russellhaering
Created: 2012-01-16 23:39:18+00:00
State: open

There is a bug introduced in 0.6.7 (specifically, by 07c27e040eb41a1f564f1d92dbe1ad07b78f3a4e) that causes double 'error' events to be emitted by https requests where the connection is refused.

Test case: https://gist.github.com/1623151

What seems to happen is that the socket error is propagated up to the http layer, which responds by trying to destroy the ClearTextStream. As of the commit referenced above, when `destroy` is called on the SecurePair, if the connection has not been established it emits an error. This logic seems broken. I'm not sure, but I think the best approach is to do one of two things:

1. Not rely on `SecurePair.prototype.destroy` to emit errors
2. Track whether an error has been emitted so we don't double emit errors