[Libwebsockets] BUG: libwebsocket_context_destroy fails to close websocket properly

Andy Green andy at warmcat.com
Fri Dec 5 00:34:19 CET 2014



On 5 December 2014 04:56:35 GMT+08:00, Tony <yellowjacketlite at gmail.com> wrote:
>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?

No that much is OK, since output.c adds the 16-bit reason itself since it knows it is LWS_WRITE_CLOSE.

-Andy

>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
>>




More information about the Libwebsockets mailing list