Subject: [hybi] WS close code equivalent to HTTP 500/Internal Server Error

From: Peter Thorson <[email-masked]>
Date: Fri, 7 Oct 2011 07:50:39 -0500

This issue came up while polishing up the error handling code for my WS implementation. There doesn't seem to be a websocket close code equivalent to HTTP 500/Internal server error.

I would like to handle situations where my endpoint catches an internal logic error and knows that continuing the connection will probably result in bad/unknown behavior but knows that it is safe enough to close the connection cleanly. 

Example: I am a server and my handler for processing websocket messages is interpreted code and that code has a syntax error. The websocket server itself is fine and can safely close the connection but clearly cannot process messages until someone fixes the missing semicolon somewhere. In an HTTP server I would return 500/Internal Server error to indicate that something on the server end screwed up and that there is probably more information in the server log files to diagnose further.

None of the current close codes (except 1006/abnormal closure - which isn't allowed on the wire) really fit. I'd rather not just drop the connection uncleanly/send back empty close frame since that provides no information about what happened and makes figuring out whose logs I should be looking at as an end application developer difficult. Browsers only report the status code itself and not the reason so sending a normal/going away error code with a more specific reason is less helpful. What are other implementations doing in this case? Would another close code for internal server error make sense?

---

From: Iñaki Baz Castillo <[email-masked]>
Date: Sat, 8 Oct 2011 22:49:53 +0200

2011/10/7 Peter Thorson <[email-masked]>:
> Browsers only report the status code itself and not the reason

The WS API tells you the status code and the reason (when present) of
the closure.

> so sending a normal/going away error code with a more specific reason is less helpful. What are other implementations doing in this case? Would another close code for internal server error make sense?

Good question :)

-- 
Iñaki Baz Castillo
<[email-masked]>

---

From: Greg Wilkins <[email-masked]>
Date: Sun, 9 Oct 2011 09:06:57 +1100

> This issue came up while polishing up the error handling code for my WS implementation. There doesn't seem to be a websocket close code equivalent to HTTP 500/Internal server error.

I've noted before that we don't have such a general close code and I
think the addition of one would be good... even at this very late
stage.

Currently in Jetty if the message handling code throws and exception,
I'm sending 1007 bad payload.  ie blaming the other end, when it is
just as likely there is a local problem that has caused the issue.
This is obviously going to wrong sometimes, but I can't see a better
option with the spec as it is.

cheers