ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.47k stars 888 forks source link

crash on close websocket in onmessage()/onopen() function #280

Open chengjianxi opened 6 years ago

chengjianxi commented 6 years ago

crash on close websocket in onmessage()/onopen() function.

        CROW_ROUTE(app, "/")
        .websocket()
        .onopen([&](crow::websocket::connection& conn) {
        CROW_LOG_INFO << "new websocket connection";
        std::lock_guard<std::mutex> _(mtx);

        conn.close();
        })
        .onmessage([&](crow::websocket::connection& conn, const std::string& data, bool is_binary) {
        std::lock_guard<std::mutex> _(mtx);

        conn.close();
    });

I got error _Left is 0xDDDDDDDD。

                                    adaptor_.close();
                                    close_connection_ = true;
                                    if (!is_close_handler_called_)
                                    {
                                        if (close_handler_)
                                            close_handler_(*this, fragment_);
                                        is_close_handler_called_ = true;
                                    }
                                    check_destroy();
                                }
                            }
                            break;
                        case 0x9: // Ping
                            {
                                send_pong(fragment_);
                            }
                            break;
                        case 0xA: // Pong
                            {
                                pong_received_ = true;
                            }
                            break;
                    }

                    fragment_.clear();
                }

break on websocekt.h line 451, fragment_.clear(); because class Connection already delete , but called fragment_.clear();

chengjianxi commented 6 years ago

I'm using VS 2015 on Windows.

Lw-Cui commented 6 years ago

This problem also happened in MacOS, Apple LLVM version 9.1.0 (clang-902.0.39.2).