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('data', this.onData);
|
||||||
this.response.removeListener('error', this.onEnd);
|
this.response.removeListener('error', this.onEnd);
|
||||||
this.response.removeListener('end', 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);
|
this.response.socket.removeListener('end', this.onEnd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Request.prototype.close = function close() {
|
Request.prototype.close = function close() {
|
||||||
this.cleanup();
|
|
||||||
|
|
||||||
if (this.request) {
|
if (this.request) {
|
||||||
try {
|
try {
|
||||||
this.request.abort();
|
this.request.abort();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
this.request = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.response) {
|
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() {
|
Request.prototype.destroy = function destroy() {
|
||||||
@ -441,10 +444,12 @@ Request.prototype._onResponse = function _onResponse(response) {
|
|||||||
this.response.on('error', this.onEnd);
|
this.response.on('error', this.onEnd);
|
||||||
this.response.on('end', this.onEnd);
|
this.response.on('end', this.onEnd);
|
||||||
|
|
||||||
// An agent socket's `end` sometimes
|
if (this.response.socket) {
|
||||||
// won't be emitted on the response.
|
this.response.socket.on('error', this.onEnd);
|
||||||
if (this.response.socket)
|
// An agent socket's `end` sometimes
|
||||||
|
// won't be emitted on the response.
|
||||||
this.response.socket.on('end', this.onEnd);
|
this.response.socket.on('end', this.onEnd);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Request.prototype._onData = function _onData(data) {
|
Request.prototype._onData = function _onData(data) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user