Repository navigation
Conversation
… killed When clickhouse-test was killed with SIGKILL (OOM, external kill), all .sh test subprocesses it had spawned with start_new_session=True became orphans: they were re-parented to init/launchd and continued running indefinitely. In Docker this was invisible because the container boundary killed everything on exit. On macOS without Docker the orphans accumulated across test runs. Solution: use session-based containment. clickhouse-test now calls os.setsid() instead of os.setpgid(0, 0), making itself a new session leader (session ID == its PID). .sh tests are spawned with preexec_fn=os.setpgrp instead of start_new_session=True, giving each test its own process group for per-test os.killpg kills while keeping it in clickhouse-test's session. Session membership survives re-parenting, so survivors can always be found with ps -A -o pid,sess even after clickhouse-test exits. run_test() in clickhouse_proc.py kills the entire session in a finally block after process.wait() returns, covering the case where clickhouse-test itself was killed. For the case where fast_test.py is killed before the finally block runs, run_test() writes the session ID to ci/tmp/clickhouse_test_session_id immediately after Popen() (before any blocking call). A new post-hook registered on darwin_fast_test_jobs reads that file and kills the session after fast_test.py exits, regardless of how it died. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
maxknv
marked this pull request as draft
April 2, 2026 15:54
Contributor
|
Workflow [PR], commit [815d652] Summary: ❌
AI ReviewSummaryThis PR introduces session-based cleanup for Findings❌ Blockers
ClickHouse Rules
Final Verdict
|
1. clickhouse-test: guard os.setsid() with a session leader check. When run_test() uses start_new_session=True, the child is already a session leader and os.setsid() raises PermissionError. The session ID already equals the PID in that case, so skipping the call is safe. 2. _kill_session / cleanup hook: replace ps -o sess with os.getsid() loop. On macOS, ps -o sess prints the controlling terminal device number, not the session ID, so it returns 0 for all detached processes. Iterating all PIDs from ps -A -o pid= and calling os.getsid() directly works correctly on both Linux and macOS. Verified with a unit test that confirms: - runner session ID == its PID after setsid() / start_new_session - .sh test (preexec_fn=os.setpgrp) is in the same session, different pgid - os.getsid() scan finds both processes - 0 processes remain after _kill_session Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
Member
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
The previous guard `os.getpid() != os.getsid(0)` only checked for session leadership, but `setsid` also fails when the caller is a process-group leader (pid == pgid), which is the normal case in a foreground shell job. Replace the guard with try/except and fall back to `setpgid(0,0)` when `setsid` fails. #101636 (comment) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
maxknv
marked this pull request as ready for review
April 7, 2026 10:25
maxknv
marked this pull request as draft
April 8, 2026 09:16
Member
Author
|
addressed by @leshikus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When running
clickhouse-teston macOS without Docker,.shtest subprocesses could survive indefinitely afterclickhouse-testorfast_test.pywas killed unexpectedly (SIGKILL, OOM).The root cause: each
.shtest was spawned withstart_new_session=True, placing it in a completely isolated session. Ifclickhouse-testwas killed before its signal handlers ran, there was no kernel mechanism to reap those children — they were re-parented tolaunchdand kept running. In Docker this was invisible because the container PID namespace killed everything on exit. On macOS without Docker the orphans accumulated across runs.Solution: session-based containment
clickhouse-testnow callsos.setsid()instead ofos.setpgid(0, 0)at startup, making itself a new session leader (session ID == its PID). Each.shtest is spawned withpreexec_fn=os.setpgrpinstead ofstart_new_session=True, giving each test its own process group (soos.killpgstill works for per-test cleanup) while keeping it inclickhouse-test's session.Session membership survives re-parenting. Even after
clickhouse-testexits and its children are adopted bylaunchd, their session ID does not change — sops -A -o pid,sesscan find them on both Linux and macOS.run_test()inclickhouse_proc.pykills the entire session in afinallyblock afterprocess.wait()returns, covering the case whereclickhouse-testitself was SIGKILL'd before its own cleanup ran.Post-hook guard for
fast_test.pybeing killed:run_test()writes the session ID toci/tmp/clickhouse_test_session_idimmediately afterPopen(), before any blocking call. A new post-hook (ci/jobs/scripts/job_hooks/clickhouse_test_cleanup_hook.py) registered ondarwin_fast_test_jobsreads that file and kills the session afterfast_test.pyexits, regardless of how it died. The file is deleted in thefinallyblock on any normal exit, so the hook is a no-op in the common case.Cleanup layers
clickhouse-testcleanup_child_processes.shtest process groupsrun_test()finallyblockclickhouse-test(incl. SIGKILL)ps -o sessfast_test.py(incl. SIGKILL)Changelog category (leave one):