mirror of https://github.com/sipwise/rtpengine.git
Sequence of events: 1) HTTP request is being handled in worker thread by calling the handler func() from within websocket_process(). 2) Handler func generates output, queues it up, and requests a `writeable` callback from within websocket_write_raw(). 3) Main LWS thread triggers writeable callback and calls websocket_dequeue(). 4) Output is given to LWS still within the main LWS thread, and finally lws_http_transaction_completed() is called to release the connection and ready it for the next HTTP connection. 5) LWS internally cleans up the connection and frees the user context (our `wc` struct). 6) The worker thread wakes up and continues to use the now invalid `wc` in order to clean up after it has done its job. Boom. The solution is to handle the `drop protocol` callback, which is triggered by LWS in the main LWS thread in step 4 from within lws_http_transaction_completed(). We call our own connection cleanup function websocket_conn_cleanup() which blocks until all jobs are removed from `wc` (step 6) and only then continue, allowing LWS to safely free the struct. Change-Id: I596a98e9b552a96aef259f4523f16fa63c287ef4pull/1164/head
parent
e4e3112498
commit
9653546f7c
Loading…
Reference in new issue