[Libwebsockets] v3.0 lws_header_table_attach bug

Andy Green andy at warmcat.com
Tue May 8 10:42:37 CEST 2018



On 05/08/2018 04:32 PM, Chropin Hu wrote:
> Dear Andy,
>           I`m trying to use the lwsws, but meet the following issue.
>           system: Ubuntu 16.04
> 
>           case 1, Run lwsws on terminal, like, ./lwsws -d 127 -c 
> "/home/develop/libwebsockets-master/etc/lwsws"
>           Result: work well!

Yes, and it works well run under systemd service as well, or you don't 
get anything from https://libwebsockets.org.

>           case 2, Run lwsws on eclipse (I use eclipse to debug the lws 
> step by step)
>           Result: not well.

...

>           I have check the log:
>           For the case 1, the log is:
> lwsws[4871]: lws_uv_timeout_cb
> lwsws[4871]: accepted new conn port 40540 on fd=17
> lwsws[4871]: lws_get_or_create_peer: creating new peer
> lwsws[4871]: _realloc: size 88: peer
> lwsws[4871]: _realloc: size 664: new server wsi
> lwsws[4871]: new wsi 0x1432590 joining vhost localhost1, tsi 0
> lwsws[4871]: lwsi_set_state(0x1432590, 0x200)
> lwsws[4871]: lws_adopt_descriptor_vhost: new wsi 0x1432590, sockfd 17
> lwsws[4871]: __lws_set_timeout: 0x1432590: 20 secs
> lwsws[4871]: lws_role_transition: 0x1432590: wsistate 0x20000015, ops h1
> lwsws[4871]: new wsi wsistate 0x20000015
> lwsws[4871]: __insert_wsi_socket_into_fds: 0x1432590: tsi=0, sock=17, 
> pos-in-fds=2
> lwsws[4871]: elops_io_uv: 0x1432590: 5
> lwsws[4871]: lws_header_table_attach: wsi 0x1432590: ah (nil) (tsi 0, 
> count = 0) in
> lwsws[4871]: _realloc: size 960: ah struct
> lwsws[4871]: _realloc: size 4096: ah data
> lwsws[4871]: _lws_create_ah: created ah 0x1432ad0 (size 4096): pool length 1
>            For the case 2, the log is:
> lwsws[4843]: accepted new conn port 40532 on fd=17
> lwsws[4843]: lws_get_or_create_peer: creating new peer
> lwsws[4843]: _realloc: size 88: peer
> lwsws[4843]: _realloc: size 664: new server wsi
> lwsws[4843]: new wsi 0x1a196d0 joining vhost localhost1, tsi 0
> lwsws[4843]: lwsi_set_state(0x1a196d0, 0x200)
> lwsws[4843]: lws_adopt_descriptor_vhost: new wsi 0x1a196d0, sockfd 17
> lwsws[4843]: __lws_set_timeout: 0x1a196d0: 20 secs
> lwsws[4843]: lws_role_transition: 0x1a196d0: wsistate 0x20000015, ops h1
> lwsws[4843]: new wsi wsistate 0x20000015
> lwsws[4843]: __insert_wsi_socket_into_fds: 0x1a196d0: tsi=0, sock=17, 
> pos-in-fds=2
> lwsws[4843]: elops_io_uv: 0x1a196d0: 5
> lwsws[4843]: lws_header_table_attach: wsi 0x1a196d0: ah (nil) (tsi 0, 
> count = 0) in
> lwsws[4843]: _lws_header_ensure_we_are_on_waiting_list: wsi: 0x1a196d0
> lwsws[4843]: _lws_change_pollfd: wsi 0x1a196d0: fd 17 events 1 -> 0
> lwsws[4843]: elops_io_uv: 0x1a196d0: 9
> lwsws[4843]: lws_adopt_descriptor_vhost: waiting for ah
> lwsws[4843]: rops_handle_POLLIN_listen: new wsi 0x1a196d0: wsistate 
> 0x20000015, role_ops h1
> 
>   The deferent is the line marked as red,
> 
>   I checked the source code:
> 
> lws_header_table_attach(struct lws *wsi, int autoservice)
> {
> struct lws_context *context = wsi->context;
> struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
> struct lws_pollargs pa;
> int n;
> 
> lwsl_info("%s: wsi %p: ah %p (tsi %d, count = %d) in\n", __func__,
>    (void *)wsi, (void *)wsi->http.ah, wsi->tsi,
>    pt->http.ah_count_in_use);
> 
> lws_pt_lock(pt, __func__);
> 
> /* if we are already bound to one, just clear it down */
> if (wsi->http.ah) {
> lwsl_info("%s: cleardown\n", __func__);
> goto reset;
> }
> 
> *n = pt->http.ah_count_in_use == context->max_http_header_pool;*
> ....
> 
> It seems that for case 2 the *context->max_http_header_pool initialed to 0*.
> I modified the main.c of lwsws, and give a value to *max_http_header_pool.*
> The issue is fixed.

... this is something to do with ulimit -n for the environment when run 
under eclipse.

It's nothing related to lws itself I think you find.  0 in 
info->max_http_header_pool means set it to the max fd count for the 
process (ie, ulimit -n).  It seems that is somehow 0 when you run it 
from eclipse.

> Is this a bug or I have miss something?

It can be a bug but I don't see how in lws.

-Andy

> Yours Chropin.
> 
> 
> 
> 
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
> 



More information about the Libwebsockets mailing list