-
Notifications
You must be signed in to change notification settings - Fork 436
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
race condition on stream close #257
Comments
Hi @virtuald, thanks for the bug report. What we'd ideally need is a simple case that reproduces the issue. Could you try to reproduce it in the example or perhaps create a test that repeatedly calls the methods and reproduces the issue? |
Well, the easiest way to reproduce this is by calling cancel from inside the data callback. It seems to me that it should be safe to call cancel at any time. https://github.com/virtuald/grpc-web/tree/cancel-race
Perhaps calling from inside the handler isn't something that should be done (I disagree -- it should be supported), so I created another example that does it from outside the handler too. function queryBooks() {
const client = new BookServiceClient(host);
const queryBooksRequest = new QueryBooksRequest();
queryBooksRequest.setAuthorPrefix("Geor");
const s = client.queryBooks(queryBooksRequest);
s.on("data", (message: Book) => {
console.log('data received', message.toObject());
});
setTimeout( () => {
console.log("timeout set");
s.cancel();
queryBooks();
}, 0);
} https://github.com/virtuald/grpc-web/tree/cancel-race2
Edit: Ha, I just realized that I provoked the race for onEnd and onMessage without realizing it. |
Thanks, that's great! Would you be interested in contributing a fix for this as well? I'm not sure we have any time to fix this in the short term. |
- ts-protoc-gen clears out the callbacks anyways - Fixes improbable-eng#257
Done. I'd love if ya'll could take a look at that and my 2 PR's on ts-protoc-gen. |
Unfortunately I personally do not have maintainer powers over |
- ts-protoc-gen clears out the callbacks anyways - Fixes improbable-eng#257
- ts-protoc-gen clears out the callbacks anyways - Fixes #257
This is for a server-side stream. The stack trace I'm getting on the client is something like so:
Uncaught TypeError: Cannot read property 'data' of null
onMessage
Array.<anonymous>
runCallbacks
This occurs when I'm clicking on my page rapidly, causing the stream to be opened/closed over and over again. I haven't tried to reproduce it using the example project.
It seems to me that perhaps the setTimeout(0) in
detach.ts
is the cause of the race condition, as there doesn't seem to be a mechanism to remove callbacks that are queued via the timeout.One workaround would be for
ts-protoc-gen
to add a check to see if listeners isnull
in the generatedonMessage
callbacks. I suspect a similar race condition exists inonEnd
also, which could be fixable via the same workaround.The text was updated successfully, but these errors were encountered: