Skip to content
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

fix(ws): calling close event with destroyed close callback #264

Merged
merged 2 commits into from Nov 29, 2022

Conversation

flisky
Copy link
Contributor

@flisky flisky commented Nov 3, 2022

I notice the following error:

image

And it's 100% reproduced when wasm-pack test --chrome.

It's a racing condition:

  • call Websocket::close, which consumes the ownership.
  • Websocket::drop is executed emmediately
    • call self.ws.close() the second time (and it doesn't matter).
    • the closures (event listeners) are dropped (and it matters).
  • self.ws.onclose is called with destroyed close callback.

Solution:

  • bindopen/close event listeners once (which I think okay, tell me if not)
  • unbind the open/message/error eventlisteners when dropping
  • trigger close event to notify the user (and unbind).

@hamza1311 hamza1311 merged commit 376aa29 into rustwasm:master Nov 29, 2022
@hamza1311
Copy link
Collaborator

Thanks for the PR! Sorry, took me so long to merge this

@flisky flisky deleted the ws-drop-racing branch January 10, 2023 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants