Skip to content

Fix fork deadlock in uexpect causing test_interactive_totp_authentication timeout - #100299

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-uexpect-fork-deadlock
Mar 21, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-uexpect-fork-deadlock

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 21, 2026 •

Copy link
Copy Markdown
Member

Fix fork deadlock in uexpect that caused test_interactive_totp_authentication to hang for 900s under MSan.

The test spawns 10 sequential interactive client sessions via pty. After 4 sessions completed, the 5th hung at Popen (stuck at os.read(errpipe_read)) because preexec_fn=os.setsid forces Python to use fork+exec, and leftover reader daemon threads (never joined) caused a multi-threaded fork deadlock.

Two fixes:

  1. Replace preexec_fn=os.setsid with start_new_session=True — avoids forcing the slow fork path
  2. Join the reader thread in IO.close to ensure cleanup before the next session

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100290&sha=55b637c00a57c55412341f944e3d40154b1d635f&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%203%2F6%29
#100290

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.112

…ication` timeout under MSan

The test hung at `Popen` when spawning the 5th bash process, stuck
at `os.read(errpipe_read, 50000)` for 900s until pytest-timeout killed it.

Root cause: `preexec_fn=os.setsid` forces Python to use fork+exec
instead of the safer posix_spawn/vfork path. Combined with leftover
reader daemon threads (never joined), this creates a multi-threaded
fork deadlock: a reader thread holds a lock during fork(), and the
child process deadlocks trying to acquire it.

Two fixes:
1. Replace `preexec_fn=os.setsid` with `start_new_session=True` —
   the equivalent Python 3.2+ parameter that doesn't force the slow
   fork path, avoiding multi-threaded fork deadlocks.
2. Join the reader thread in `IO.close` to ensure proper cleanup
   before the next session is created.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100290&sha=55b637c00a57c55412341f944e3d40154b1d635f&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%203%2F6%29

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d971f12]

Summary: ✅


AI Review

Summary

This PR updates tests/integration/helpers/uexpect.py to avoid a Python fork deadlock in integration tests by replacing preexec_fn=os.setsid with start_new_session=True, and it additionally joins the reader thread during IO.close cleanup. The change is narrowly scoped, matches the reported failure mode, and appears safe/correct for CI helper behavior.

ClickHouse Rules

Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ➖
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Mar 21, 2026
@alexey-milovidov alexey-milovidov self-assigned this Mar 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 21, 2026
Merged via the queue into master with commit 024a955 Mar 21, 2026
148 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-uexpect-fork-deadlock branch March 21, 2026 23:49
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants