aboutsummaryrefslogtreecommitdiff
path: root/lib/http.js
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-01-18 12:58:16 -0800
committerisaacs <i@izs.me>2013-01-18 12:58:16 -0800
commit3d7818fc42c5f9af2aeccf9d75ad6a2372179f28 (patch)
treedc768380326c509df5d90616bdfcbfb6d22b6264 /lib/http.js
parentfc3547bc828dfcaca83e9c4415743fb201a821f6 (diff)
parent9c2c84546347df599840aceb59605b4b6d38a549 (diff)
downloadandroid-node-v8-3d7818fc42c5f9af2aeccf9d75ad6a2372179f28.tar.gz
android-node-v8-3d7818fc42c5f9af2aeccf9d75ad6a2372179f28.tar.bz2
android-node-v8-3d7818fc42c5f9af2aeccf9d75ad6a2372179f28.zip
Merge remote-tracking branch 'ry/v0.8' into master
Conflicts: AUTHORS ChangeLog src/node_version.h test/simple/test-buffer.js
Diffstat (limited to 'lib/http.js')
-rw-r--r--lib/http.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/http.js b/lib/http.js
index 417b3c9d20..c8bec11212 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -970,7 +970,24 @@ exports.ServerResponse = ServerResponse;
ServerResponse.prototype.statusCode = 200;
function onServerResponseClose() {
- this._httpMessage.emit('close');
+ // EventEmitter.emit makes a copy of the 'close' listeners array before
+ // calling the listeners. detachSocket() unregisters onServerResponseClose
+ // but if detachSocket() is called, directly or indirectly, by a 'close'
+ // listener, onServerResponseClose is still in that copy of the listeners
+ // array. That is, in the example below, b still gets called even though
+ // it's been removed by a:
+ //
+ // var obj = new events.EventEmitter;
+ // obj.on('event', a);
+ // obj.on('event', b);
+ // function a() { obj.removeListener('event', b) }
+ // function b() { throw "BAM!" }
+ // obj.emit('event'); // throws
+ //
+ // Ergo, we need to deal with stale 'close' events and handle the case
+ // where the ServerResponse object has already been deconstructed.
+ // Fortunately, that requires only a single if check. :-)
+ if (this._httpMessage) this._httpMessage.emit('close');
}
ServerResponse.prototype.assignSocket = function(socket) {