diff options
author | isaacs <i@izs.me> | 2013-04-22 08:52:42 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-04-22 09:54:04 -0700 |
commit | 01e29202193cfc4257d6c638b8c08b7fcc2c9931 (patch) | |
tree | 4e626d7f79d3745ba877738052c70fbebfafa962 /lib | |
parent | 1d794ec43e5a5b72ab4aeafa91d2e54fd92503b8 (diff) | |
download | android-node-v8-01e29202193cfc4257d6c638b8c08b7fcc2c9931.tar.gz android-node-v8-01e29202193cfc4257d6c638b8c08b7fcc2c9931.tar.bz2 android-node-v8-01e29202193cfc4257d6c638b8c08b7fcc2c9931.zip |
http: Don't try to destroy nonexistent sockets
Fixes #3740
In the case of pipelined requests, you can have a situation where
the socket gets destroyed via one req/res object, but then trying
to destroy *another* req/res on the same socket will cause it to
call undefined.destroy(), since it was already removed from that
message.
Add a guard to OutgoingMessage.destroy and IncomingMessage.destroy
to prevent this error.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/http.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/http.js b/lib/http.js index ac6b1c6bf7..4a4fe94f3e 100644 --- a/lib/http.js +++ b/lib/http.js @@ -349,8 +349,12 @@ IncomingMessage.prototype._read = function(n) { }; +// It's possible that the socket will be destroyed, and removed from +// any messages, before ever calling this. In that case, just skip +// it, since something else is destroying this connection anyway. IncomingMessage.prototype.destroy = function(error) { - this.socket.destroy(error); + if (this.socket) + this.socket.destroy(error); }; @@ -467,8 +471,16 @@ OutgoingMessage.prototype.setTimeout = function(msecs, callback) { }; +// It's possible that the socket will be destroyed, and removed from +// any messages, before ever calling this. In that case, just skip +// it, since something else is destroying this connection anyway. OutgoingMessage.prototype.destroy = function(error) { - this.socket.destroy(error); + if (this.socket) + this.socket.destroy(error); + else + this.once('socket', function(socket) { + socket.destroy(error); + }); }; |