Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

Commit

Permalink
Fixes behavior on hangups and aborts
Browse files Browse the repository at this point in the history
The existing behavior on hangups and aborts disregarded the parameters
passed in via options, and failed at a number smaller than maxRetries.
This is counter intuitive, undocumented, and not modifiable from the
external API.

This pull request defaults maxHangups and maxAborts to maxRetries and
changes the underlying code to actually use those values rather than
hard coded values.
  • Loading branch information
rcoh committed Dec 11, 2013
1 parent 3586b16 commit cc79dfa
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 cc79dfa

Please sign in to comment.