-
-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crow::Crow<>::stop()
stops asio::io_context
too soon
#498
Comments
A quick fix could be instead of invoking Not sure if this has its own pitfalls, just couldn't think of something better ATM. |
I think another solution would be to have the server wait for all websocket connections to be closed before calling |
I have been thinking, do we have a convenient way to wait for certain events like the closing of WebSocket connection, in Crow or ASIO? |
Not exactly, what we do have is a list of all open websocket connections. We can use that to check whether or not they were all closed before stopping the server. |
It can be attacked by malicious clients if they hold the connections for ever, to prevent the server from stopping. I just give up another websocket library called "uWebSockets" and turn to CrowCpp, because uWebSockets can't safely stop, it always crashes on Windows, but the developer of uWebSockets says it's my fault.
|
If one calls
crow::websocket::connection::close()
followed bycrow::Crow<>::stop()
right away, they are probably doomed.I only skimmed through the code. Looks like the issue was,
crow::websocket::connection::close()
uses asio's dispatch function so if called from a different thread other than within the one(s) running io_context loop, it only post the task to the queue. It will need some time for the io_context to pick it up and execute. Andcrow::Crow<>::stop()
stops io_contexts immediately, so the tasks are untouched and the connections remain in a connected state.The text was updated successfully, but these errors were encountered: