Skip to content

The WebSocket connection is unexpectedly closed, and the program crashes. #1842

@LetAmericaGreatAgain

Description

@LetAmericaGreatAgain

I want to push video frames via WebSocket, where each frame is 3,110,400 bytes in size. After the connection is established, the client browser sends a message, and after the server receives it, it calls this->play(ws) to start pushing the video frames. However, after sending a few frames, the program crashes, and I don't know why the WebSocket connection is being closed. It has been confirmed that the issue is related to WebSocket, and it might be due to the size of the data being sent. The relevant code is as follows:

app->ws<PerSocketData>(api, {
            .compression = uWS::DISABLED,
            .maxPayloadLength = 64 * 1024 * 1024,
            .idleTimeout = 60,
            .maxBackpressure = 1024 * 1024 * 1024,
            .closeOnBackpressureLimit = false,
            .resetIdleTimeoutOnSend = true,
            .sendPingsAutomatically = true,
            .upgrade = nullptr,
            .open = [](uWS::WebSocket<false, true, PerSocketData> *ws) {
                std::cout << "open..." << std::endl;
            },
            .message = [this](uWS::WebSocket<false, true, PerSocketData> *ws, std::string_view message,
                              uWS::OpCode opCode) {
                std::thread t([this, ws]() {
                    this->play(ws);
                });
                t.detach();
void play(uWS::WebSocket<false, true, PerSocketData> *ws) {
    try {
        video::start([ws](std::string_view frame_data) -> void {
            ws->send(frame_data, uWS::OpCode::BINARY);
        });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions