Closed tomtomau closed 2 months ago
I've tried adding
on('error')
listeners, and I can successfully "catch" theError
on the server side, but it seems like the library automatically closes the connection when this occurs? Is this the intended behaviour or am I likely not holding it correctly?
Yes, it is. The connection is closed with the 1009
status code when this happens. See https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1.
Ok, thanks for clarify that I'm at least not holding it incorrectly!
I'm not familiar with the rest of the specs, do they prescribe that a server must close the connection with 1009
? Or just that if the server closes the connection due to exceeding the maximum payload size then it should use the 1009
code, and the only valid condition for returning 1009
code is due to exceeding the maximum payload size (i.e. don't use it for other reasons)
It seems unnecessary to have the server close the connection when it receives a message that is too large, when being able to handle it internally on the server as an "error" (in my case, sending back a message to the client to tell them it was too large) but continue to keep the connection open for more messages, but I'm not sure if that's just a fundamental misunderstanding of mine of the websocket protocol
I think it is not mandatory but the behavior is common in the WebSocket implementations.
I'm closing this as answered.
Is there an existing issue for this?
Description
Hey there, I've searched high and low in the docs/issues and haven't quite found an answer to my issues.
Ideally, I'm wanting to handle the receiving a
maxPayload
message such that I can keep the connection to the client open and send it a message to tell it the message was too large.I've tried adding
on('error')
listeners, and I can successfully "catch" theError
on the server side, but it seems like the library automatically closes the connection when this occurs? Is this the intended behaviour or am I likely not holding it correctly?ws version
8.16.0
Node.js Version
v18
System
Expected result
Don't close the connection when the error occurs
Actual result
It closes the connection when the error occurs
Attachments
No response