[Libwebsockets] Which are the events received by the callback when "lws_context_destroy" is called

Gilles Printemps gprintemps at gmail.com
Tue Nov 19 11:30:31 CET 2019


Hi,
I would like to understand which events should be received by the callback
when "lws_context_destroy" function is called.

Currently, in debug mode, I have the following trace:

[2019/11/19 10:01:57:4407] I: lws_context_destroy: ctx 0xffff99a03280
[2019/11/19 10:01:57:4408] I: lws_destroy_event_pipe
[2019/11/19 10:01:57:4409] I: __lws_close_free_wsi: 0xffff98203500: caller:
ctx destroy
>>> Reason [30] wsi [0xffff98203500] session [(nil)] data [(nil)]
>>> Protocol [0xffff9a202820]
[2019/11/19 10:01:57:4411] I: lws_vhost_unbind_wsi: vh default:
count_bound_wsi 0
[2019/11/19 10:01:57:4412] I: lws_vhost_destroy1
[2019/11/19 10:01:57:4413] I: lws_context_destroy2: ctx 0xffff99a03280
>>> Reason [28] wsi [0xffffe73b2750] session [(nil)] data [(nil)]
>>> Protocol [0xffff9a202820]
[2019/11/19 10:01:57:4414] I: __lws_vhost_destroy2: 0xffff98203880
[2019/11/19 10:01:57:4415] I:   __lws_vhost_destroy2: Freeing vhost
0xffff98203880
[2019/11/19 10:01:57:4416] I: lws_context_destroy3: ctx 0xffff99a03280 freed
WebSocket Server stopped


But in release mode (with -O2 optimisation), I have something different and
strange:

>>> Reason [1] wsi [0xaaaaedae9eb0] session [(nil)] data [(nil)]
>>> Protocol [(nil)]
>>> Reason [-8707407386353682176] wsi [(nil)] session [0xffffa4b03928] data
[0xffffa431c8c0]
Segmentation fault (core dumped)


It is ending by a segmentation fault because I'm trying to retrieve the
protocol with a wsi which is equal to NULL a the entrance of the callback.

int WebSocketServer::callback(struct lws *wsi,enum lws_callback_reasons
reason,void *session,void *data,size_t len) {
  const struct lws_protocols *protocol=NULL;
  Tools::debug(">>> Reason [%ld] wsi [%p] session [%p] data
[%p]\n",reason,wsi,session,data);
  Tools::debug(">>> Protocol [%p]\n",lws_get_protocol(wsi));

 Seem also the reason is wrong!!!

Where did the strange behavior can come from?
Did I miss again something the calling "lws_context_destroy"?
Initialisation logs are the same in debug/release (see below) and I'm not
doing anything between the init and the destroy.

[2019/11/19 10:28:26:6552] I: Initial logging level 8
[2019/11/19 10:28:26:6553] I: Libwebsockets version: 3.2.0 v3.2.0
[2019/11/19 10:28:26:6553] I: IPV6 not compiled in
[2019/11/19 10:28:26:6553] I:  LWS_DEF_HEADER_LEN    : 4096
[2019/11/19 10:28:26:6554] I:  LWS_MAX_PROTOCOLS     : 5
[2019/11/19 10:28:26:6554] I:  LWS_MAX_SMP           : 1
[2019/11/19 10:28:26:6555] I:  sizeof (*info)        : 648
[2019/11/19 10:28:26:6555] I:  SYSTEM_RANDOM_FILEPATH: '/dev/urandom'
[2019/11/19 10:28:26:6556] I:  HTTP2 support         : available
[2019/11/19 10:28:26:6558] I: context created
[2019/11/19 10:28:26:6562] I: Using event loop: poll
[2019/11/19 10:28:26:6563] I: Default ALPN advertisment: h2,http/1.1
[2019/11/19 10:28:26:6563] I:  default timeout (secs): 20
[2019/11/19 10:28:26:6564] I:  Threads: 1 each 1024 fds
[2019/11/19 10:28:26:6565] I:  mem: context:          5144 B (1048 ctx + (1
thr x 4096))
[2019/11/19 10:28:26:6565] I:  mem: http hdr size:   (4096 + 976), max
count 1024
[2019/11/19 10:28:26:6567] I:  mem: pollfd map:       8192 B
[2019/11/19 10:28:26:6568] I:  mem: platform fd map:  8192 B
[2019/11/19 10:28:26:6571] I:  Compiled with OpenSSL support
[2019/11/19 10:28:26:6571] I:  SSL disabled: no
LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
[2019/11/19 10:28:26:6571] I: Creating Vhost 'default' port 9000, 1
protocols, IPv6 off
[2019/11/19 10:28:26:6572] I: lws_vhost_bind_wsi: vh default:
count_bound_wsi 1
[2019/11/19 10:28:26:6573] I:  Listening on port 9000
[2019/11/19 10:28:26:6573] I:  mem: per-conn:          696 bytes + protocol
rx buf
[2019/11/19 10:28:26:6574] I:  canonical_hostname = ubuntu
[2019/11/19 10:28:26:6574] I: lws_plat_drop_app_privileges: not changing
group
[2019/11/19 10:28:26:6574] I: lws_plat_drop_app_privileges: not changing
user
[2019/11/19 10:28:26:6574] I: lws_cancel_service
WebSocket Server [9000] started
>>> Reason [31] wsi [0xfffffa1d6340] session [(nil)] data [(nil)]
>>> Protocol [(nil)]
>>> Reason [71] wsi [0xaaaaedaec7c0] session [(nil)] data [(nil)]
>>> Protocol [0xaaaaedaeb180]
[2019/11/19 10:28:26:6577] I: lws_protocol_init
>>> Reason [27] wsi [0xfffffa1d5fc0] session [(nil)] data [(nil)]
>>> Protocol [0xaaaaedaeb180]


BR
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20191119/8fb088ee/attachment-0001.htm>


More information about the Libwebsockets mailing list