grpc-js: 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.
This commit is contained in:
Richard Willis 2020-04-18 09:16:41 +01:00
parent 7eca188ae1
commit 4e7b94ab35
1 changed files with 1 additions and 1 deletions

View File

@ -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();
}
}
}