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

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.

@bellinitte bellinitte force-pushed the websocket_send_closed branch 4 times, most recently from 622ea01 to 807b66a Compare November 19, 2024 20:07
@bellinitte bellinitte force-pushed the websocket_send_closed branch from 807b66a to 712b60d Compare November 19, 2024 20:44
@bellinitte bellinitte force-pushed the websocket_send_closed branch from 712b60d to be34664 Compare November 19, 2024 21:06
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

@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
…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