Permalink
Browse files

distinguish request timeouts from other socket errors in the error me…

…ssage
  • Loading branch information...
1 parent f1f303e commit 70e95769612be294b9d432ce1be0b2575bc954e4 @dannycoates committed Jul 10, 2012
Showing with 9 additions and 2 deletions.
  1. +7 −2 lib/endpoint.js
  2. +2 −0 test/endpoint_test.js
View
9 lib/endpoint.js
@@ -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()
}
}
@@ -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)
@@ -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)
}
View
2 test/endpoint_test.js
@@ -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)
})
@@ -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)
})

0 comments on commit 70e9576

Please sign in to comment.