Skip to content

Fix ConnManager exit code race - #201

Merged
Karol Zadora-Przylecki (karolz-ms) merged 1 commit into
mainfrom
danegsta-fix-connmanager-exit-code-race
Jul 1, 2026
Merged

Fix ConnManager exit code race#201
Karol Zadora-Przylecki (karolz-ms) merged 1 commit into
mainfrom
danegsta-fix-connmanager-exit-code-race

Conversation

@danegsta

Copy link
Copy Markdown
Member

ConnManager could drop a recorded non-zero process exit code when process exit raced serve cancellation, causing HMP clients to receive the default exit code 0.

This updates the exit-code feeder to prefer an already-available ExitHandler result even when the serve context is also canceled. The helper is split out so the timing-sensitive path has deterministic regression coverage.

Validation:

  • make test-prereqs
  • go test -count 1 -parallel 32 ./internal/termpty
  • make test
  • make lint

Fixes: #199

Prefer an already-recorded process exit code when serve cancellation races process exit, so HMP clients do not receive the default exit code 0 after a non-zero process exit. Add deterministic coverage for the timing path.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a timing-sensitive race in ConnManager where a recorded non-zero process exit code could be dropped when process exit raced serve-context cancellation, causing HMP clients to receive the default exit code 0. Previously, the exit-code feeder goroutine used a single select between ExitHandler.Exited() and serveCtx.Done(); when cancellation won the race, it closed exitCodeCh without ever sending the code. The refactor extracts the feeder logic into a testable helper that prefers an already-available exit result even when the serve context is also canceled.

Changes:

  • Extracted the exit-code feeding logic into sendProcessExitCode/sendExitCode helpers, adding an inner select that re-checks Exited() when serveCtx.Done() fires so an already-recorded exit code is still forwarded.
  • Added process package import to conn_manager.go.
  • Added a deterministic regression test (TestSendProcessExitCodePrefersExitedProcessAfterServeCancel) that exercises the both-ready timing scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/termpty/conn_manager.go Splits the exit-code feeder into sendProcessExitCode/sendExitCode; the cancellation branch now re-checks Exited() so a recorded exit code is forwarded instead of dropped.
internal/termpty/conn_manager_test.go Adds a regression test asserting the recorded exit code is sent when process exit and serve cancellation are both ready.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@karolz-ms
Karol Zadora-Przylecki (karolz-ms) merged commit a4a98aa into main Jul 1, 2026
12 checks passed
@karolz-ms
Karol Zadora-Przylecki (karolz-ms) deleted the danegsta-fix-connmanager-exit-code-race branch July 1, 2026 19:53
@danegsta

Copy link
Copy Markdown
Member Author

/backport to release/0.25

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

Started backporting to release/0.25: https://github.com/microsoft/dcp/actions/runs/28544273580

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

David Negstad (@danegsta) backport PR couldn't be created automatically, please create the backport PR manually!

Open backport PR into release/0.25.

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

Successfully merging this pull request may close these issues.

ConnManager can send exit code 0 when process exit races shutdown

3 participants