request: fix socket hangup.
This commit is contained in:
parent
291c7f72fe
commit
22c5014c49
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user