Skip to content

Commit

Permalink
Fix: timeout on socket, timeout after redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Petukhov committed Jan 23, 2012
1 parent 70c5b63 commit fc0f04b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ Request.prototype.request = function () {
self.req.end()
return
}
if (self.timeout && self.timeoutTimer) clearTimeout(self.timeoutTimer)
if (self.timeout && self.timeoutTimer) {
clearTimeout(self.timeoutTimer);
self.timeoutTimer = null;
}
self.emit('error', error)
}
if (self.onResponse) self.on('error', function (e) {self.onResponse(e)})
Expand Down Expand Up @@ -491,6 +494,17 @@ Request.prototype.request = function () {
e.code = "ETIMEDOUT"
self.emit("error", e)
}, self.timeout)

// Set additional timeout on socket - in case if remote
// server freeze after sending headers
self.req.setTimeout(self.timeout, function(){
if (self.req) {
self.req.abort()
var e = new Error("ESOCKETTIMEDOUT")
e.code = "ESOCKETTIMEDOUT"
self.emit("error", e)
}
});
}

self.req.on('error', clientErrorHandler)
Expand Down

0 comments on commit fc0f04b

Please sign in to comment.