Crow icon indicating copy to clipboard operation
Crow copied to clipboard

Websocket: Message is not send when closing connection

Open autoantwort opened this issue 3 months ago • 3 comments

When I test the following code:

 CROW_WEBSOCKET_ROUTE(crowApp, "/test")
     .onopen([&](crow::websocket::connection &conn) {
             conn.send_text("Error with query params");
             conn.close("error", crow::websocket::PolicyViolated);
     })
     .onclose([&](crow::websocket::connection &conn, const std::string &reason, uint16_t code) {
         // This gets called twice?
     })

I never get the Error with query params message.

autoantwort avatar Sep 30 '25 16:09 autoantwort

Can you write a PR containing a test for this?

gittiver avatar Sep 30 '25 18:09 gittiver

possibly a bug, i am not a websockets expert, but code uses asio::post for send_text and asio::dispatch for close, so maybe it overrides and closes before the text is send.

gittiver avatar Sep 30 '25 18:09 gittiver

This was not fixed by https://github.com/CrowCpp/Crow/pull/1101, please reopen.

autoantwort avatar Oct 10 '25 23:10 autoantwort