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(ext/websocket): don't throw exception when sending to closed socket #26932

Merged
merged 3 commits into from
Nov 21, 2024
Merged

fix(ext/websocket): don't throw exception when sending to closed socket #26932

merged 3 commits into from
Nov 21, 2024

Conversation

bellinitte
Copy link
Contributor

@bellinitte bellinitte commented Nov 19, 2024

The WebSocket specification for the send function says:

The browser will throw an exception if you call send() when the connection is in the CONNECTING state. If you call send() when the connection is in the CLOSING or CLOSED states, the browser will silently discard the data.

and:

Exceptions

InvalidStateError DOMException

Thrown if WebSocket.readyState is CONNECTING.

This pull request fixes the current behavior to match the specification. Also, I believe it fixes #17586.

@CLAassistant
Copy link

CLAassistant commented Nov 19, 2024

CLA assistant check
All committers have signed the CLA.

Unverified

No user is associated with the committer email.
Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM

Unverified

No user is associated with the committer email.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@bartlomieju bartlomieju merged commit 8f7787f into denoland:main Nov 21, 2024
17 checks passed
bartlomieju pushed a commit that referenced this pull request Nov 28, 2024

Unverified

No user is associated with the committer email.
…et (#26932)

[The WebSocket specification for the `send`
function](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)
says:

> The browser will throw an exception if you call `send()` when the
connection is in the `CONNECTING` state. If you call `send()` when the
connection is in the `CLOSING` or `CLOSED` states, the browser will
silently discard the data.

and:

> ### Exceptions
> 
> `InvalidStateError`
[`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException)
> 
> Thrown if
[`WebSocket.readyState`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState)
is `CONNECTING`.

This pull request fixes the current behavior to match the specification.
Also, I believe it fixes #17586.
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.

Uncaught InvalidStateError: readyState not OPEN
4 participants