[Libwebsockets] BUG: libwebsocket_context_destroy fails to close websocket properly

Andy Green andy at warmcat.com
Fri Dec 5 00:37:29 CET 2014



On 5 December 2014 04:40:03 GMT+08:00, Tony <yellowjacketlite at gmail.com> wrote:
>While investigating my question regarding my issue with proper client
>side
>shutdown, I think I uncovered a bug.
>
>In libwebsocket_context_destroy, libwebsocket_close_and_free_session is
>called with a shutdown reason of LWS_CLOSE_STATUS_NOSTATUS.  However
>the
>code of libwebsocket_close_and_free_session, it expects the 'reason' to
>be
>anything but LWS_CLOSE_STATUS_NOSTATUS.
>
>Here's the line...
>
>    if (old_state == WSI_STATE_ESTABLISHED &&
>                      reason != LWS_CLOSE_STATUS_NOSTATUS) {
>   // perform shutdown step 1
>    }
>
>I'm not sure of the correct fix, but I __think__ either
>libwebsocket_context_destroy should pass in, say,
>LWS_CLOSE_STATUS_NORMAL,
>or the above if statement should be changed to read...
>
>    if (old_state == WSI_STATE_ESTABLISHED &&
>                      reason == LWS_CLOSE_STATUS_NOSTATUS) {
>   // perform shutdown step 1
>    }

No the idea is if we close with a status code, lws should try to inform the other side about what happened.  But if you close with NOSTATUS, it means just unilaterally close the socket from our side without sending a status to the peer.  For example if you noticed the peer had gone away, you would definitely want to use NOSTATUS.

I think we could do more with close status, but it's always legal for the other side to hang up, so mostly we just use NOSTATUS.

-Andy




More information about the Libwebsockets mailing list