-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
send
on a closed WebSocket should not throw an exception
#1515
Comments
This changed over the years but originally the browser implementations threw and I think (this pre-dates me) it is the reason why it was implemented in this way. The spec is not clear in this regard and it is confirmed by the fact that different implementations have different behaviors. I think what we have is actually somehow consistent with Node.js streams where an error is emitted if the stream is closed. We throw and do not emit, but only when not using a callback. If ws is wrapped in a I'm not sure if it makes sense to change this. It would be a breaking change for no clear benefit in my opinion. I'm also not sure what the correct behavior should be. |
I disagree; I think the spec is clear that In addition to the spec references I've quoted above, consider the description of
If |
I was talking about the RFC, not the WHATWG spec which is "new" and browser focused. What should be in your opinion the expected behavior? Buffer messages indefinitely with no feedback to the user other than an always increasing |
Ah, I think I may have misunderstood the intent of this module -- I had thought that its My use case is focused on testing the browser/client side of a WebSocket client/server application. I was using |
We strive to be browser compatible but there are some differences. Here is a non comprehensive list of differences:
I'm fine with changing |
Thanks for the details! Your proposal sounds good to me. |
I'm wondering is there any equivalent of a |
@TrevorSundberg see #964.
Yes use a callback or check for |
- If the `readyState` attribute is `CONNECTING`, throw an exception. - If the `readyState` attribute is `CLOSING` or `CLOSED` - Increase the `bufferedAmount` attribute by the length of the `data` argument in bytes. - If specified, call the `callback` function with an error. Fixes #1515
- If the `readyState` attribute is `CONNECTING`, throw an exception. - If the `readyState` attribute is `CLOSING` or `CLOSED` - Increase the `bufferedAmount` attribute by the length of the `data` argument in bytes. - If specified, call the `callback` function with an error. Fixes #1515
- If the `readyState` attribute is `CONNECTING`, throw an exception. - If the `readyState` attribute is `CLOSING` or `CLOSED` - Increase the `bufferedAmount` attribute by the length of the `data` argument in bytes. - If specified, call the `callback` function with an error. Fixes #1515
- If the `readyState` attribute is `CONNECTING`, throw an exception. - If the `readyState` attribute is `CLOSING` or `CLOSED` - Increase the `bufferedAmount` attribute by the length of the `data` argument in bytes. - If specified, call the `callback` function with an error. Fixes #1515
- If the `readyState` attribute is `CONNECTING`, throw an exception. - If the `readyState` attribute is `CLOSING` or `CLOSED` - Increase the `bufferedAmount` attribute by the length of the `data` argument in bytes. - If specified, call the `callback` function with an error. Fixes #1515
- If the `readyState` attribute is `CONNECTING`, throw an exception. - If the `readyState` attribute is `CLOSING` or `CLOSED` - Increase the `bufferedAmount` attribute by the length of the `data` argument in bytes. - If specified, call the `callback` function with an error. Fixes #1515
- If the `readyState` attribute is `CONNECTING`, throw an exception. - If the `readyState` attribute is `CLOSING` or `CLOSED` - Increase the `bufferedAmount` attribute by the length of the `data` argument in bytes. - If specified, call the `callback` function with an error. Fixes #1515
issue.
Description
For compatibility with browser implementations, the HTML standard, and RFC 6455, calling
send
on aWebSocket
whosereadyState
isCLOSING
orCLOSED
should discard the data and not throw an exception. (As a QOL issue, it may log an error to the console.)Currently it throws an exception such as "WebSocket is not open: readyState 2 (CLOSING)".
Reproducible in:
Steps to reproduce:
Start a WebSocket server on port 9000.
Run the following in node:
Expected result:
All result in "sent" being printed to the console.
Actual result:
Error: WebSocket is not open: readyState 2 (CLOSING)
, with an exception stack trace pointing towebsocket.js:320
.References:
HTML Standard:
Note that an exception must be thrown only in the
CONNECTING
state, and the "following list" does not include any steps that involve throwing an exception.RFC 6455:
Note "abort the following steps"; i.e. stop processing, but do not raise an exception.
The text was updated successfully, but these errors were encountered: