request: fix socket hangup.

This commit is contained in:
Christopher Jeffrey 2016-12-19 07:21:40 -08:00
parent 291c7f72fe
commit 22c5014c49
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -292,21 +292,20 @@ Request.prototype.cleanup = function cleanup() {
this.response.removeListener('data', this.onData);
this.response.removeListener('error', this.onEnd);
this.response.removeListener('end', this.onEnd);
if (this.response.socket)
if (this.response.socket) {
this.response.socket.removeListener('error', this.onEnd);
this.response.socket.removeListener('end', this.onEnd);
}
}
};
Request.prototype.close = function close() {
this.cleanup();
if (this.request) {
try {
this.request.abort();
} catch (e) {
;
}
this.request = null;
}
if (this.response) {
@ -322,8 +321,12 @@ Request.prototype.close = function close() {
;
}
}
this.response = null;
}
this.cleanup();
this.request = null;
this.response = null;
};
Request.prototype.destroy = function destroy() {
@ -441,10 +444,12 @@ Request.prototype._onResponse = function _onResponse(response) {
this.response.on('error', this.onEnd);
this.response.on('end', this.onEnd);
// An agent socket's `end` sometimes
// won't be emitted on the response.
if (this.response.socket)
if (this.response.socket) {
this.response.socket.on('error', this.onEnd);
// An agent socket's `end` sometimes
// won't be emitted on the response.
this.response.socket.on('end', this.onEnd);
}
};
Request.prototype._onData = function _onData(data) {