Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
distinguish request timeouts from other socket errors in the error me…
Browse files Browse the repository at this point in the history
…ssage
  • Loading branch information
dannycoates committed Jul 10, 2012
1 parent f1f303e commit 70e9576
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/endpoint.js
Expand Up @@ -59,6 +59,7 @@ module.exports = function (inherits, EventEmitter) {
var expireTime = clock - r.options.timeout
if (r.lastTouched <= expireTime) {
this.emit("timeout", r)
r.timedOut = true
r.abort()
}
}
Expand Down Expand Up @@ -208,10 +209,12 @@ module.exports = function (inherits, EventEmitter) {

// this = request
function gotError(error) {
var msg = this.node.ip + ':' + this.node.port + ' error: '
msg += this.timedOut ? 'request timed out' : error.message
this.node.failed(
{ reason: error.message
, attempt: this
, message: this.node.ip + ':' + this.node.port + ' error: ' + error.message
, message: msg
}
, this)
this.node.setHealthy(false)
Expand Down Expand Up @@ -258,10 +261,12 @@ module.exports = function (inherits, EventEmitter) {

// this = response
function gotAborted() {
var msg = this.request.node.ip + ':' + this.request.node.port + ' error: '
msg += this.request.timedOut ? 'response timed out' : 'connection aborted'
this.request.node.failed(
{ reason: 'aborted'
, attempt: this.request
, message: this.request.node.ip + ':' + this.request.node.port + ' error: connection aborted'
, message: msg
}
, this.request)
}
Expand Down
2 changes: 2 additions & 0 deletions test/endpoint_test.js
Expand Up @@ -119,6 +119,7 @@ describe("Endpoint", function () {
setTimeout(function () {
s.close()
assert.equal(error.reason, "socket hang up")
assert.equal(/request timed out$/.test(error.message), true)
done()
}, 40)
})
Expand Down Expand Up @@ -149,6 +150,7 @@ describe("Endpoint", function () {
setTimeout(function () {
s.close()
assert.equal(error.reason, "aborted")
assert.equal(/response timed out$/.test(error.message), true)
done()
}, 60)
})
Expand Down

0 comments on commit 70e9576

Please sign in to comment.