Skip to content

process: fix flaky TestBackgroundInGroupInterruptChildReadsTerminal - #7958

Draft
denik wants to merge 1 commit into
mainfrom
fix-interrupt-pid-race
Draft

denik wants to merge 1 commit into
mainfrom
fix-interrupt-pid-race

Conversation

@denik

@denik denik commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Changes

TestBackgroundInGroupInterruptChildReadsTerminal (added in #7832) flaked on Linux with "the interrupt did not end the helper before the grace period".

The helper's child script recorded the grandchild's PID with $!, which the shell knows right after fork. At that point the forked shell still has the TERM trap and has not yet exec'd sleep. If the group SIGTERM lands in that window it can be lost: sleep 300 keeps running and holds the stdout pipe, so Wait blocks until WaitDelay (the 10s grace period) and the test gives up at 5s. At timeout, a process dump in a local run showed the sh child gone and sleep 300 still alive, reparented.

The grandchild now writes its own PID ($$) from a freshly exec'd shell, which has the default TERM disposition, and then execs sleep. Once the PID is recorded, a SIGTERM always ends it. The test checks the same things as before.

The production code is unchanged. The other tests in the package that use $! don't catch TERM: they either leave the default disposition or ignore TERM, and an ignored disposition survives fork and exec.

Tests

  • Before: 16 concurrent loops of -race -count=40 locally, 13 failures with the same message.
  • After: the same stress, 640/640 passed.
  • The test still fails when withNewSession is disabled (child left in the terminal's session), so it still catches the SIGTTIN regression it was written for.

Dashboard: error/3824, libs/process.TestBackgroundInGroupInterruptChildReadsTerminal. Flaky on PRs: 3+ failures in 7 days (to 2026-11-25), for example:

interrupt_linux_test.go:103: the interrupt did not end the helper before the grace period
--- FAIL: TestBackgroundInGroupInterruptChildReadsTerminal (5.04s)

This pull request and its description were written by Isaac.

The helper script recorded the grandchild's PID with $!, which is known
right after fork, while the forked shell still has the TERM trap and has
not yet exec'd sleep. A group SIGTERM landing in that window can be lost,
so sleep keeps running and holds the output pipe until WaitDelay (the 10s
grace period) and the test times out at 5s.

The grandchild now writes its own PID from a fresh shell with the default
TERM disposition and then execs sleep.

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions github-actions Bot added the test-only-fix PRs that update failing of flaky tests without changing CLI code. label Nov 25, 2026
@eng-dev-ecosystem-bot

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: b6fdb0e

Run: 45575882890

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 272 19 4:48
💚​ aws-windows-latest-4core-16gb 1 274 17 7:30
💚​ azure linux-2core-8gb 1 271 19 4:29
💚​ azure-windows-latest-4core-16gb 1 273 17 7:38
💚​ gcp linux-2core-8gb 1 272 19 5:02
💚​ gcp-windows-latest-4core-16gb 1 274 17 7:59
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 6 slowest tests (at least 2 minutes):
duration env testname
7:57 gcp-windows-latest-4core-16gb TestAccept
7:35 azure-windows-latest-4core-16gb TestAccept
7:28 aws-windows-latest-4core-16gb TestAccept
4:11 gcp linux-2core-8gb TestAccept
3:26 azure linux-2core-8gb TestAccept
3:25 aws linux-2core-8gb TestAccept

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

factory-generated test-only-fix PRs that update failing of flaky tests without changing CLI code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants