Skip to content

Commit

Permalink
grpc-js: Remove watcher from queue before calling watcher callback. F…
Browse files Browse the repository at this point in the history
…ixes grpc#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.
  • Loading branch information
badsyntax committed Apr 18, 2020
1 parent 7eca188 commit 4e7b94a
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 4e7b94a

Please sign in to comment.