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

Commit bc62d7a

Browse files
committed
Defer plugin callbacks to next tick
Nock 13.x has changed to better reflect the semantics of modern Node versions. A side effect of this was the test `CloudantClient/#db using listeners/with ComplexPlugin2` failing with the `end` event being triggered twice, causing two done callbacks. The changes suggest that nock moved the abort event to the next tick. This ensures our plugin callbacks also move so that abort is handled correctly.
1 parent 06287dd commit bc62d7a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/clientutils.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017, 2018 IBM Corp. All rights reserved.
1+
// Copyright © 2017, 2021 IBM Corp. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ var processState = function(r, callback) {
6767
if (r.abort) {
6868
// [1] => Client has called for the request to be aborted.
6969
abort();
70-
callback(new Error('Client issued abort')); // no retry
70+
setImmediate(callback, new Error('Client issued abort')); // no retry
7171
return;
7272
}
7373

@@ -77,15 +77,15 @@ var processState = function(r, callback) {
7777
sendResponseToClient(r.state.abortWithResponse, r.clientStream, r.clientCallback);
7878
var err = new Error('Plugin issued abort');
7979
err.skipClientCallback = true;
80-
callback(err); // no retry
80+
setImmediate(callback, err); // no retry
8181
return;
8282
}
8383

8484
if (r.state.retry && r.state.attempt < r.state.maxAttempt) {
8585
// [3] => One or more plugins have called for the request to be retried.
8686
abort();
8787
debug('Plugin issued a retry.');
88-
callback(); // retry
88+
setImmediate(callback); // retry
8989
return;
9090
}
9191

@@ -104,7 +104,7 @@ var processState = function(r, callback) {
104104

105105
if (!r.state.sending) {
106106
// [4] => Request has not yet been sent. Still processing 'onRequest' hooks.
107-
callback(); // continue
107+
setImmediate(callback); // continue
108108
return;
109109
}
110110

@@ -120,7 +120,7 @@ var processState = function(r, callback) {
120120
}
121121

122122
// [5] => Return response to awaiting client.
123-
callback(new Error('No retry requested')); // no retry
123+
setImmediate(callback, new Error('No retry requested')); // no retry
124124
};
125125

126126
// execute a specified hook for all plugins

0 commit comments

Comments
 (0)