-
-
Notifications
You must be signed in to change notification settings - Fork 510
Description
Firsly, I really appreciate your amazing work. It literally changed my life :D.
And apologies for my short English skills as I don't natively use it.
The text below is logging from my application which is under development currently.
---> Normal cycle: accept - open - close
[2022-08-28 08:45:44.399] [__PERFKIT:BACKEND] [info] [web_terminal.cpp:185] * Accepting terminal WebSocket from: 127.0.0.1
[2022-08-28 08:45:44.399] [__PERFKIT:BACKEND] [info] [web_terminal.cpp:192] * Opening WebSocket: 127.0.0.1
[2022-08-28 08:45:47.139] [__PERFKIT:BACKEND] [info] [web_terminal.cpp:163] * (127.0.0.1) Closing websocket: ��
[2022-08-28 08:45:47.139] [__PERFKIT:BACKEND] [info] [web_terminal.cpp:180] * WebSocket closed. (0.000 seconds)
--->
---> Stopping application while there are any active websocket connection:
---> Cleanup logic is not called!
[2022-08-28 08:45:47.562] [__PERFKIT:BACKEND] [info] [web_terminal.cpp:185] * Accepting terminal WebSocket from: 127.0.0.1
[2022-08-28 08:45:47.562] [__PERFKIT:BACKEND] [info] [web_terminal.cpp:192] * Opening WebSocket: 127.0.0.1
[2022-08-28 08:45:51.855] [info] CMD: quit
[2022-08-28 08:45:51.855] [__PERFKIT] [trace] invoking as tokens
[2022-08-28 08:45:51.855] [info] Disposing application
[2022-08-28 08:45:51.855] [info] Destroying application instance
[2022-08-28 08:45:51.855] [info] Disposing terminal.
(2022-08-27 23:45:51) [INFO ] Closing IO service 0000018D4EEB7190
(2022-08-27 23:45:51) [INFO ] Closing main IO service (0000018D4EF028A0)
(2022-08-27 23:45:51) [INFO ] Exiting.
It seems active websockets does not receive onclose() callback call on application disposal.
It causes problem as I usually dynamically allocate userdata object on onaccept() routine, to implement notification without explicit client request. (Holding connection references outside of on*() callback routines will make calling send_text|send_binary() at random timing available)
Currently I'm releasing allocated memory from onclose() callback routine. However, if it's not properly called on crow::App's stop sequence, it results in memory leak.
I just found your
TODOmessage inside ofstop()method after writing this ... I believe you have a plan to resolve this. Please just take below content as an idea ...
It seems there's already logic to handle it, however, it seems there are a few problems with it.
- Newly connected websocket instances are not registered within
Crow::::websockets_field automatically. Thus, user have to make call toadd_websocket()andremove_websocket()on their own websocket handler routine. - However, any access to
websocket_field is not properly protected with any mutex or critical section. Link toadd_websocket, remove_websocket - And, even if
websocket_access routines are made atomic, as they are invoked prior to actualhttp_server::stop()call, new websocket connection can be made during existing websocket cleanup routines, which will makeadd_websocketcall, after copyingwebsocket_to_closecontent.