websocket icon indicating copy to clipboard operation
websocket copied to clipboard

When Send is called on a closed WebSocket, no error returned.

Open dmitshur opened this issue 10 years ago • 3 comments

The problem is already mentioned in code, see wrapper.go#L97-L98.

I can confirm the issue. Send returns nil error, but there is a WebSocket is already in CLOSING or CLOSED state. error in the console.

image

Any ideas on how we can fix this?

dmitshur avatar Jan 26 '15 02:01 dmitshur

Just a dumb idea, but can we check the ReadyState value in Send?

dmitshur avatar Jan 26 '15 03:01 dmitshur

Just a dumb idea, but can we check the ReadyState value in Send?

I don't see any technical reason that we couldn't. I wonder if there's a way that we could capture the exception and return it, though.

mjohnson9 avatar Jan 26 '15 03:01 mjohnson9

I wonder if there's a way that we could capture the exception and return it, though.

I agree that would be better. It's clean, correct, consistent, and doesn't incur an extra performance penalty every time sending on an open socket. I would only fall back to checking ReadyState as a backup, if we can't get anything else to work.

dmitshur avatar Jan 26 '15 04:01 dmitshur