lua-websockets icon indicating copy to clipboard operation
lua-websockets copied to clipboard

Clarify on_error/on_close behavior

Open moteus opened this issue 10 years ago • 3 comments

Async client/server on_error calls if there some error befor ws handshake done (IO error/SSL handshake/Invalid token/ protocol) . And in this case on_close did not call. on_close calls if ws handshake done. In case of IO error we call on_close with (false, 1001, "Going away"). And in this caseon_error` did not call.

Is it correct behavior?

moteus avatar Mar 06 '15 07:03 moteus

I think on_close should be called when the client will not be able to work with the ws any more. You raised one good question: If the connection has never been open, should on_close and on_error be called anyways?

I tend to call on_close and on_error also when the connection failed. This would make async error handling easier.

BTW: on_error should always be calls before on_close. (This is how node.js does it with sockets).

lipp avatar Mar 06 '15 11:03 lipp

May be we should call on_close only if there was on_open event. And call on_error on any errors. But there may be cases when other side just close connection and in this case may be we shuld just call on_close with status 1001?

moteus avatar Mar 06 '15 12:03 moteus

ok, agree.

lipp avatar Mar 06 '15 12:03 lipp