Skip to content

Commit

Permalink
Remove watcher from queue before calling watcher callback. Fixes #1352
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
badsyntax committed Apr 18, 2020
1 parent 7eca188 commit 2d981d9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/grpc-js/src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ export class ChannelImplementation implements Channel {
const watchersCopy = this.connectivityStateWatchers.slice();
for (const watcherObject of watchersCopy) {
if (newState !== watcherObject.currentState) {
watcherObject.callback();
clearTimeout(watcherObject.timer);
this.removeConnectivityStateWatcher(watcherObject);
watcherObject.callback();
}
}
}
Expand Down

0 comments on commit 2d981d9

Please sign in to comment.