[Libwebsockets] BUG: libwebsocket_context_destroy fails to close websocket properly

Tony yellowjacketlite at gmail.com
Thu Dec 4 21:56:35 CET 2014


One more thing...(this is a minor issue, though it might have impacts
elsewhere in the code):

Looking further it looks like you are attempting to include a close
'reason' in the close packet, but the code that does that work is broken
resulting no reason being sent.

I __think__ the issue is in libwebsocket_close_and_free_session where it
calls libwebsocket_write.  A buffer is passed in with room for a reason
code (+2), but the buffer's length is passed in as 0.  See below...

        /* make valgrind happy */
        memset(buf, 0, sizeof(buf));
        n = libwebsocket_write(wsi,
                &buf[LWS_SEND_BUFFER_PRE_PADDING + 2],
                                0, LWS_WRITE_CLOSE); // <-- I think the
zero is wrong?

On Thu, Dec 4, 2014 at 3:40 PM, 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
>     }
>
> --
> Tony
>



-- 
Tony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20141204/360b6889/attachment-0001.html>


More information about the Libwebsockets mailing list