fix: cleanup socker error handler on response
This commit is contained in:
parent
a58e38454f
commit
171892c669
2 changed files with 17 additions and 1 deletions
|
@ -98,7 +98,7 @@ app.callback = function(){
|
||||||
return function(req, res, next){
|
return function(req, res, next){
|
||||||
var ctx = self.createContext(req, res);
|
var ctx = self.createContext(req, res);
|
||||||
next = next || ctx.onerror;
|
next = next || ctx.onerror;
|
||||||
ctx.socket.once('error', next);
|
ctx.onSocketError(next);
|
||||||
co.call(ctx, gen)(next);
|
co.call(ctx, gen)(next);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -488,4 +488,20 @@ module.exports = {
|
||||||
attachment: function() {
|
attachment: function() {
|
||||||
return this.response.attachment.apply(this.response, arguments);
|
return this.response.attachment.apply(this.response, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke `fn` on socket errors and
|
||||||
|
* handle cleanup on response.
|
||||||
|
*
|
||||||
|
* @param {Function} fn
|
||||||
|
* @api private
|
||||||
|
*/
|
||||||
|
|
||||||
|
onSocketError: function(fn){
|
||||||
|
var sock = this.socket;
|
||||||
|
sock.once('error', fn);
|
||||||
|
this.res.on('finish', function(){
|
||||||
|
sock.removeListener('error', fn);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue