Skip to content

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

@mincequi

Description

@mincequi

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdiscussionThe viability / implementation of the issue is up for debate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions