Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 6011243

Browse files
authored
Merge pull request #301 from cloudant/fix-multiple-callback-execution
Prevent client executing done callback multiple times
2 parents 9f255ac + 4d9fd4c commit 6011243

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# UNRELEASED
22
- [FIXED] Add missing `maxAttempt` parameter to TypeScript definition.
33
- [FIXED] Include client initialization callback in TypeScript definition.
4+
- [FIXED] Prevent client executing done callback multiple times.
45
- [FIXED] Removed test and lint data that bloated npm package size.
56
- [FIXED] Support Cloudant query when using promises request plugin.
67

lib/client.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@ class CloudantClient {
267267
};
268268

269269
async.forever(function(done) {
270+
request.doneCallback = done;
271+
request.done = false;
272+
273+
// Fixes an intermittent bug where the `done` callback is executed
274+
// multiple times.
275+
done = function(error) {
276+
if (request.done) {
277+
debug('Callback was already called.');
278+
return;
279+
}
280+
request.done = true;
281+
return request.doneCallback(error);
282+
};
283+
270284
request.options = Object.assign({}, options); // new copy
271285
request.response = undefined;
272286

0 commit comments

Comments
 (0)