Skip to content

Commit

Permalink
Merge pull request godotengine#97913 from Faless/fix/websocket_closin…
Browse files Browse the repository at this point in the history
…g_transition

[WS] Detect disconnection due to protocol errors
  • Loading branch information
Repiteo committed Nov 12, 2024
2 parents ab5a539 + 6cdfc8c commit caff0ff
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions modules/websocket/wsl_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,37 @@ void WSLPeer::poll() {
close(-1);
return;
}
if (wslay_event_get_close_sent(wsl_ctx) && wslay_event_get_close_received(wsl_ctx)) {
// Clean close.
wslay_event_context_free(wsl_ctx);
wsl_ctx = nullptr;
close(-1);
return;
if (wslay_event_get_close_sent(wsl_ctx)) {
if (wslay_event_get_close_received(wsl_ctx)) {
// Clean close.
wslay_event_context_free(wsl_ctx);
wsl_ctx = nullptr;
close(-1);
return;
} else if (!wslay_event_get_read_enabled(wsl_ctx)) {
// Some protocol error caused wslay to stop processing incoming events, we'll never receive a close from the other peer.
close_code = wslay_event_get_status_code_sent(wsl_ctx);
switch (close_code) {
case WSLAY_CODE_MESSAGE_TOO_BIG:
close_reason = "Message too big";
break;
case WSLAY_CODE_PROTOCOL_ERROR:
close_reason = "Protocol error";
break;
case WSLAY_CODE_ABNORMAL_CLOSURE:
close_reason = "Abnormal closure";
break;
case WSLAY_CODE_INVALID_FRAME_PAYLOAD_DATA:
close_reason = "Invalid frame payload data";
break;
default:
close_reason = "Unknown";
}
wslay_event_context_free(wsl_ctx);
wsl_ctx = nullptr;
close(-1);
return;
}
}
}
}
Expand Down

0 comments on commit caff0ff

Please sign in to comment.