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

Commit

Permalink
Merge pull request #15 from Ink/master
Browse files Browse the repository at this point in the history
Fixes behavior on hangups and aborts
  • Loading branch information
dannycoates committed Dec 11, 2013
2 parents 9fa54d0 + cc79dfa commit a3e2f10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/request_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function RequestSet(pool, options, callback) {
this.attemptsLeft = attemptsFu(options, pool)
this.attempts = this.attemptsLeft

this.maxHangups = options.maxHangups || 2
this.maxHangups = options.maxHangups || pool.options.maxRetries;
this.hangups = 0

this.maxAborts = options.maxAborts || 2
this.maxAborts = options.maxAborts || pool.options.maxRetries;
this.aborts = 0

if (!options.retryDelay && options.retryDelay !== 0) {
Expand Down Expand Up @@ -52,7 +52,7 @@ function handleResponse(err, response, body) {
if (err.reason === "socket hang up") { this.hangups++ }
else if (err.reason === "aborted") { this.aborts++ }

if (this.attemptsLeft > 0 && this.hangups < 2 && this.aborts < 2) {
if (this.attemptsLeft > 0 && this.hangups < this.maxHangups && this.aborts < this.maxAborts) {
this.pool.onRetry(err)
if (delay > 0) {
setTimeout(this.doRequest.bind(this), delay)
Expand Down
8 changes: 4 additions & 4 deletions test/requestset_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ describe("RequestSet", function () {
})
})

it("retries hangups once then fails", function (done) {
it("retries hangups identically to other requests then fails", function (done) {
var p = {
i: 0,
options: { maxRetries: 5 },
get_node: function () { return this.nodes[this.i++]},
onRetry: function () {},
length: 3,
nodes: [{ request: hangup_request }, { request: hangup_request }, { request: succeeding_request }]
nodes: [{ request: hangup_request }, { request: hangup_request }, { request: hangup_request }, { request: hangup_request }, { request: hangup_request }, { request: succeeding_request }]
}
RequestSet.request(p, {}, function (err, res, body) {
assert.equal(err.reason, "socket hang up")
Expand All @@ -139,14 +139,14 @@ describe("RequestSet", function () {
})
})

it("retries aborts once then fails", function (done) {
it("retries aborts identically to other requests then fails", function (done) {
var p = {
i: 0,
options: { maxRetries: 5 },
get_node: function () { return this.nodes[this.i++]},
onRetry: function () {},
length: 3,
nodes: [{ request: aborted_request }, { request: aborted_request }, { request: succeeding_request }]
nodes: [{ request: aborted_request }, { request: aborted_request }, { request: aborted_request }, { request: aborted_request}, { request: aborted_request}, { request: aborted_request} ]
}
RequestSet.request(p, {}, function (err, res, body) {
assert.equal(err.reason, "aborted")
Expand Down

0 comments on commit a3e2f10

Please sign in to comment.