Skip to content

The continuation frame causes the connection to drop #42

Open
@doufu3344

Description

@doufu3344

void WebSocket::handleFrame(const Frame::Header& frameHeader) {
switch (frameHeader.opcode) {
case Frame::OPCODE_CONTINUATION:
if(m_lastOpcode < 0) {
throw std::runtime_error("[oatpp::web::protocol::websocket::WebSocket::handleFrame()]: Invalid communication state.");
}
readPayload(frameHeader, nullptr);
break;
case Frame::OPCODE_TEXT:
if(checkForContinuation(frameHeader)) {
readPayload(frameHeader, nullptr);
} else {
throw std::runtime_error("[oatpp::web::protocol::websocket::WebSocket::handleFrame()]: Invalid communication state. OPCODE_CONTINUATION expected");
}
break;

In the above code, the m_lastOpcode member is not updated when processing a frame with opcode=Frame::OPCODE_CONTINUATION and fin=true , so when processing Frame::OPCODE_TEXT for the next frame, checkForContinuation() returns false and throws an exception. This results in a service disconnection.
bool WebSocket::checkForContinuation(const Frame::Header& frameHeader) {
if(m_lastOpcode == Frame::OPCODE_TEXT || m_lastOpcode == Frame::OPCODE_BINARY) {
return false;
}
if(frameHeader.fin) {
m_lastOpcode = -1;
} else {
m_lastOpcode = frameHeader.opcode;
}
return true;
}

The same problem exists with asynchronous implementations

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