Skip to content
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

Endless calls to onerror handler for websocket connection if client closes uncleanly #895

Open
mincequi opened this issue Sep 8, 2024 · 0 comments
Labels
bug Something isn't working discussion The viability / implementation of the issue is up for debate

Comments

@mincequi
Copy link

mincequi commented Sep 8, 2024

Hi there,

i experience a serious issue (which is perfectly reproducible), that crashes the server, if a client closes connection uncleanly (like wifi outage). This happens with version 1.2.0, as well as with latest master a9e7b73.

If the client crashed, the server stucks in calling the onerror handler repeatedly with reason "uncleanly".

This somehow seems related to #549 .

Edit: this very naive fix seems to do the trick:

diff --git a/include/crow/websocket.h b/include/crow/websocket.h
index 7c6694e32..0e2822ba5 100644
--- a/include/crow/websocket.h
+++ b/include/crow/websocket.h
@@ -725,9 +725,11 @@ namespace crow // NOTE: Already documented in "crow/app.h"
             {
                 // Note that if the close handler was not yet called at this point we did not receive a close packet (or send one)
                 // and thus we use ClosedAbnormally unless instructed otherwise
-                if (!is_close_handler_called_)
+                if (!is_close_handler_called_) {
                     if (close_handler_)
                         close_handler_(*this, "uncleanly", code);
+                    is_close_handler_called_ = true;
+                }
                 handler_->remove_websocket(this);
                 if (sending_buffers_.empty() && !is_reading)
                     delete this;
@gittiver gittiver added bug Something isn't working discussion The viability / implementation of the issue is up for debate labels Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discussion The viability / implementation of the issue is up for debate
Projects
None yet
Development

No branches or pull requests

2 participants