[Libwebsockets] We met an issue when using libwebsocket and fixed it, how can I submit the patch

张立峰 lifeng.zhang at melot.cn
Thu Jun 4 08:16:49 CEST 2020


Hi, Andy:


Recently, we met a crash on windows.
Some thing like this: 

The program is a windows client using websocket protocol.

1. We create a thread as the service thread, calling lws_service. We intended to use this thread to service may ws client connections. -- Mark as thread A

2. And we call lws_client_connect_via_info from another thread to create the wsi struct.  -- Mark as thread B

3. After some normal case testing, every thing is fine. Then we disabled the local network (from windows`s device manager) to test network failed case.
4. It will crash. 

5. After some code debug effort, we know that the wsi created in lws_client_connect_via_info, freed twice. One is before  lws_client_connect_via_info return and in the thread B,  anther is in the  lws_service and in the thread A (founding a closed socket, I think, in our case is in windows-service.c(_lws_plat_service_tsi)?)


I tried to fix it like this:
1. In the /libwebsockets/lib/roles/http/client/client-handshake.c
2. move following code a little down, before a successfull wsi return:

 if (__insert_wsi_socket_into_fds(wsi->context, wsi))
           goto try_next_result_closesock;



I am not very confident for this code change. Please give some help, if this is right fix?


Best wishes
Terry Zhang
2020-6-4  







 
------------------ Original ------------------
From:  "Andy Green"<andy at warmcat.com>;
Date:  Wed, Mar 4, 2020 09:03 PM
To:  "张立峰"<lifeng.zhang at melot.cn>; "libwebsockets"<libwebsockets at ml.libwebsockets.org>; 

Subject:  Re: [Libwebsockets] We met an issue when using libwebsocket and fixed it, how can I submit the patch

 



On 3/4/20 10:28 AM, 张立峰 wrote:
> Hi, everyone:
> 
> When using libwebsockets as a client to communicate a ws server, we 
> write out many messages in a queue when receive 
> a LWS_CALLBACK_CLIENT_WRITEABLE. This may cause the ws server to close 
> our connection.
> 
> We found that when lws_write return value is smaller than requested, the 
> connection will be close when we use lws_write next time.
> 
> After check the source code of libwebsockets, we found the issue cause:
> 
> The "wsi->ws->inside_frame" is not set to "0" after wsi->buflist_out has 
> been sent. This will cause the wrong coded ws frame been sent.

Thanks, I modified it a little bit for the cases ws is not enabled for 
build or it's http and not ws connection, and pushed it on master and 
v3.2-stable.

-Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20200604/b5040cf8/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-crash.diff
Type: application/octet-stream
Size: 1645 bytes
Desc: not available
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20200604/b5040cf8/attachment.obj>


More information about the Libwebsockets mailing list