Skip to content

fix(execd): send WSCloseTakenOver close frame on takeover during initial writes (#2377) - #2378

Merged
Pangjiping merged 1 commit into
opensandbox-group:mainfrom
markankamaransheogarat-sys:fix/execd-pty-takeover-close-code-2377
Oct 25, 2026
Merged

Pangjiping merged 1 commit into
opensandbox-group:mainfrom
markankamaransheogarat-sys:fix/execd-pty-takeover-close-code-2377

Conversation

@markankamaransheogarat-sys

Copy link
Copy Markdown

Closes #2377

Problem

In PR #2376, evictClose was introduced using conn.WriteControl(websocket.CloseMessage, ...) to safely send a WSCloseTakenOver (4001) close frame without deadlocking on connMu. However, the initial eviction hook registered before the initial replay and connected frame writes still executed a bare conn.Close() without sending a close frame.

Consequently, if a concurrent ?takeover=1 arrived while the holder was sending its initial replay frame or connected frame, the evicted client received an abnormal closure (1006) instead of 4001 (WSCloseTakenOver), preventing clients from distinguishing deliberate takeovers from unexpected network disconnects.

Solution

  • Updated the initial eviction hook in PTYSessionWebSocket to call evictClose(model.WSCloseTakenOver, model.WSErrCodeTakenOver) before cancelOnce(), matching the post-initial hook. Since WriteControl is concurrent-safe with unlocked websocket writes, this cleanly transmits the close frame without racing.
  • Added regression test TestPTYWS_TakeoverDuringInitialReplayClosesHolderWithCloseCode in pty_ws_test.go, verifying that evicting a holder while its initial replay write is blocked transmits the 4001 close frame.

Verification

  • Executed go test -v -run "^TestPTYWS_Takeover" ./pkg/web/controller (all 5 takeover tests passed).
  • Executed the full pkg/web/controller test suite under Linux: all tests PASS.

@github-actions github-actions Bot added component/execd size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 24, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T14:05:43.795103Z 8988c18 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8988c18508

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Pangjiping Pangjiping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Pangjiping
Pangjiping merged commit 8abe6f0 into opensandbox-group:main Oct 25, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/execd size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

execd: PTY takeover during initial replay/connected writes still closes holder with 1006 instead of 4001

3 participants