Skip to content

Commit 2d981d9

Browse files
committed
Remove watcher from queue before calling watcher callback. Fixes #1352
In the case where a new watcher is synchronously added to the watcher queue via the watcher callback, this can result in the callback being called multiple times. To support this case, the watcher needs to be move removed from the queue before calling the watcher callback.
1 parent 7eca188 commit 2d981d9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/grpc-js/src/channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ export class ChannelImplementation implements Channel {
381381
const watchersCopy = this.connectivityStateWatchers.slice();
382382
for (const watcherObject of watchersCopy) {
383383
if (newState !== watcherObject.currentState) {
384-
watcherObject.callback();
385384
clearTimeout(watcherObject.timer);
386385
this.removeConnectivityStateWatcher(watcherObject);
386+
watcherObject.callback();
387387
}
388388
}
389389
}

0 commit comments

Comments
 (0)