-
Notifications
You must be signed in to change notification settings - Fork 655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grpc-js: waitForReady called multiple times #1352
Comments
That does look like a bug, but I don't know what could be causing that to happen. |
In your screencast, you are running that code in a function |
Hi. Yes i've checked, that method is called only once, and the ready callback is called 3 times. I'm using a pretty standard gRPC Java server on the backend. I've done some digging and it looks like there's some recursion happening which results in multiple watcherObjects being queued which results in the waitForReady callback being called multiple times. It starts here: (note the callback ( within grpc-node/packages/grpc-js/src/client.ts Lines 179 to 183 in 03fdeed
grpc-node/packages/grpc-js/src/channel.ts Lines 451 to 461 in 03fdeed
Now when grpc-node/packages/grpc-js/src/channel.ts Lines 404 to 410 in 03fdeed
So I think the fix is to remove the watcher before calling the callback. So change this code: grpc-node/packages/grpc-js/src/channel.ts Lines 406 to 408 in 03fdeed
To this: clearTimeout(watcherObject.timer);
this.removeConnectivityStateWatcher(watcherObject);
watcherObject.callback(); I've tested this change and seems to work, the waitForReady callback is only called once, but I'm really not familiar with this code and I could be completely misunderstanding all of this. Also not sure the side-effects of making this change. |
I think I do see a situation that could cause what you're seeing: if the state transition that triggers the I'd be happy to make the change you described, or to accept a PR that makes that change. |
Cool yes I think that makes sense. Am happy to make a PR for this, but will only get to doing it sometime tomorrow (BST). |
…#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.
…#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.
…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.
I've added a PR with #1368 but it doesn't look like the builds are running. Should I close the PR and re-open? |
No need to add a service to the server to test the client.
No need to add a service to the server to test the client.
grpc-js: Client waitForReady callback fix. Fixes #1352
Problem description
When using
client.waitForReady
, the ready callback is called multiple times (3 times in this case). Is this is the expected behaviour? I expected it to be called only once. Perhaps I'm misunderstanding the API.Reproduction steps
I'm constructing the gRPC client (which extends from Client.ts).
Environment
@grpc/[email protected]
Screencast
The text was updated successfully, but these errors were encountered: