OCPBUGS-84721: Fix WebSocket InvalidStateError in pod terminal#16377
OCPBUGS-84721: Fix WebSocket InvalidStateError in pod terminal#16377Leo6Leo wants to merge 1 commit intoopenshift:mainfrom
Conversation
WSFactory.send() only checked if the WebSocket instance existed before calling send(), which throws InvalidStateError when the connection is still in CONNECTING state. This race condition occurs during terminal reconnects or container switches when resize/input events fire before the handshake completes. Guard send() with a readyState === OPEN check to silently drop messages on connections that are not yet ready.
|
@Leo6Leo: This pull request references Jira Issue OCPBUGS-84721, which is invalid:
Comment The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Leo6Leo The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Central YAML (inherited) Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
📜 Recent review details🔇 Additional comments (2)
📝 WalkthroughWalkthroughThis change modifies the 🚥 Pre-merge checks | ✅ 12✅ Passed checks (12 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Review rate limit: 9/10 reviews remaining, refill in 6 minutes. Comment |
|
@Leo6Leo: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Analysis / Root cause:
WSFactory.send()only checked if the WebSocket instance existed (this.ws && this.ws.send(data)) before sending. When the WebSocket is still inCONNECTINGstate (e.g. during terminal reconnects or container switches), resize/input events from xterm.js can firesend()before the handshake completes, throwingInvalidStateError. CLIoc execis unaffected since this is purely a frontend timing issue.Solution description:
Guard
send()withreadyState === WebSocket.OPENso messages are silently dropped on connections that aren't ready. Added unit tests covering all WebSocket readyState values.Screenshots / screen recording:
Test setup:
source ./contrib/oc-environment.sh && ./bin/bridgeTest cases:
InvalidStateErrorBrowser conformance:
Additional info:
Jira: https://redhat.atlassian.net/browse/OCPBUGS-84721
Backport to
release-4.18planned.Reviewers and assignees:
Summary by CodeRabbit