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

Ensure readyState is set to SR_CLOSED on successful WebSocket closure #693

Conversation

nnabeyang
Copy link
Contributor

This PR fixes an issue where the readyState was not properly set to SR_CLOSED when the WebSocket closed successfully.

Changes:

  • Previously, during a successful WebSocket closure, the readyState remained at SR_CLOSING and was not updated to SR_CLOSED.
  • With this fix, the readyState is now set to SR_CLOSED before the delegate method responsible for handling the WebSocket closure is called.

Copy link

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nnabeyang, thanks for the contribution.
I think that the line you added is correct but not in the best place. I added a comment.

@@ -1113,6 +1113,8 @@ - (void)_pumpWriting
}
}

self.readyState = SR_CLOSED;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this code go inside the if(!_failed)?
What's the state of the WebSocket if we send a command to close it and it fails to close for whatever reason? Is it in closing state? is it open?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cipolleschi Thank you! You're right, it does make more sense to put it inside if(!_failed). I fixed it.

2d81c50

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in 2204e53.

@nnabeyang nnabeyang deleted the fix-websocket-readystate-closed-before-closure-delegate branch October 15, 2024 21:06
nnabeyang added a commit to lisb/SocketRocket that referenced this pull request Oct 16, 2024
…facebookincubator#693)

Summary:
This PR fixes an issue where the `readyState` was not properly set to `SR_CLOSED` when the WebSocket closed successfully.

### Changes:
- Previously, during a successful WebSocket closure, the `readyState` remained at `SR_CLOSING` and was not updated to `SR_CLOSED`.
- With this fix, the `readyState` is now set to `SR_CLOSED` before the delegate method responsible for handling the WebSocket closure is called.

Pull Request resolved: facebookincubator#693

Reviewed By: nlutsenko

Differential Revision: D64108852

Pulled By: cipolleschi

fbshipit-source-id: d683d951e3b0069f1e909c091e8bc4e5d5066dab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants