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

Commit 0bd1087

Browse files
committed
Ensure callback called for late errors
Add a flag when the execution loop is stopped. Force a callback on error if the flag is set. Update documentation to clarify behaviour of retry plugin. Fixes #456
1 parent f96de70 commit 0bd1087

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# UNRELEASED
2+
- [FIXED] Hang caused by plugins (i.e. retry plugin) preventing callback execution
3+
by attempting to retry on errors received after starting to return the response body.
24
- [DEPRECATED] This library is now deprecated and will be EOL on Dec 31 2021.
35

46
# 4.4.0 (2021-06-18)

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,10 @@ var cloudant = Cloudant({ url: myurl, maxAttempt: 5, plugins: [ { iamauth: { iam
511511
- `retryErrors`
512512
513513
Automatically retry a request on error (e.g. connection reset errors)
514-
_(default: true)_.
514+
_(default: true)_. Note that this will only retry errors encountered
515+
_before_ the library starts to read response body data. After that point
516+
any errors (e.g. socket timeout reading from the server) will be returned
517+
to the caller (via callback or emitted `error` depending on the usage).
515518
516519
- `retryInitialDelayMsecs`
517520

lib/clientutils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ var processState = function(r, callback) {
120120
}
121121

122122
// [5] => Return response to awaiting client.
123+
r.state.final = true; // flags that we are terminating the loop
123124
setImmediate(callback, new Error('No retry requested')); // no retry
124125
};
125126

@@ -157,7 +158,7 @@ var wrapCallback = function(r, done) {
157158
if (error) {
158159
runHooks('onError', r, error, function() {
159160
processState(r, function(stop) {
160-
if (stop && !stop.skipClientCallback) {
161+
if ((stop && !stop.skipClientCallback) || r.state.final) {
161162
r.clientCallback(error, response, body);
162163
}
163164
done(stop);

0 commit comments

Comments
 (0)