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

The continuation frame causes the connection to drop #42

Open
doufu3344 opened this issue Mar 24, 2023 · 0 comments
Open

The continuation frame causes the connection to drop #42

doufu3344 opened this issue Mar 24, 2023 · 0 comments

Comments

@doufu3344
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant