Skip to content

fix: block SIGPIPE on the ADBC and pyo3 runtime threads - #510

Merged
vuanhphung merged 3 commits into
mainfrom
fix/block-sigpipe-adbc-pyo3
Dec 1, 2026
Merged

vuanhphung merged 3 commits into
mainfrom
fix/block-sigpipe-adbc-pyo3

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Builds on #509 (merged), which blocks SIGPIPE on the kernel's C-ABI and telemetry runtime threads. Two other runtimes run kernel socket I/O on threads they own, and neither was hooked:

  • The ADBC driver's own runtime (RuntimeHandle::create). When a Go program loads the driver through a cgo driver manager, a SIGPIPE raised on one of its workers kills the process.
  • The pyo3 per-session runtime. Python ignores SIGPIPE by default, but an app that restores SIG_DFL, a common CLI idiom, is killed instead of getting EPIPE.

This PR re-exports the kernel's block_sigpipe_on_current_thread from the crate root as #[doc(hidden)]. That is the smallest surface the sibling crates can use through their existing path dependency. Both runtimes now pass it to on_thread_start, so it covers workers and blocking-pool threads. The pyo3 builder moves from Session.__new__ into KernelRuntime::build so a test can check the real runtime; it is otherwise unchanged. Caller-injected ADBC runtimes and napi (Node ignores SIGPIPE) are left alone.

How exposed each runtime is today depends on its TLS backend. pyo3 builds with tls-rustls, which writes TLS records with writev, so any write after a peer reset raises SIGPIPE. ADBC uses the default tls-native: tokio-native-tls has only poll_write (tokio-native-tls/src/lib.rs:149,205 @02c1aeb), so on Linux its TLS writes end in std's send(MSG_NOSIGNAL). ADBC is therefore exposed only through plain-HTTP writev today; the hook matches the C-ABI runtime and covers any later rustls build.

Cross-driver state

Host State Notes
Go via an ADBC driver manager (cgo) Exposed on plain-HTTP writes → Fixed (this PR) TLS writes on tls-native builds already use MSG_NOSIGNAL (see above)
Python (pyo3) Session threads exposed if the app restores SIG_DFL → Fixed (this PR) CPython sets SIG_IGN by default (Modules/signalmodule.c:1913 @v3.13.0); databricks-sql-python has no SIGPIPE handling
Go (C ABI), ODBC Fixed by #509 —
Node.js (napi) Not exposed Node sets SIG_IGN (src/node.cc:544 @v22.11.0)
JDBC Not applicable Doesn't use the kernel

No other Databricks driver blocks SIGPIPE itself; this follows #509's thread-scoped mask.

Testing

  • New Linux-only tests, owned_runtime_threads_block_sigpipe (adbc) and session_runtime_threads_block_sigpipe (pyo3), build the real runtime (RuntimeHandle::create, KernelRuntime::build). Each runs a task on a worker and on a spawn_blocking thread and checks SIGPIPE's bit in SigBlk, after first asserting that the test thread doesn't block it. fix: block SIGPIPE on kernel runtime threads #509's helper is cfg(test) in the kernel crate, so each crate carries a ten-line copy. fix: block SIGPIPE on kernel runtime threads #509's end-to-end SIG_DFL test isn't duplicated.
  • No Rust toolchain was available locally, so CI is the build, lint and test gate. CI passes except macOS dSYM (the known 45-minute timeout, same on main) and Security Scan, which flags chrono-tz@0.10.4 (RUSTSEC-2026-0555) that main's fix(adbc): support named Arrow timezones #515 brought in; this PR adds no dependencies. Highlights:
    • ADBC native + C ABI (toolchain 1.89): clippy -D warnings and 99 tests pass, including owned_runtime_threads_block_sigpipe; the dlopen smoke test passes.
    • The six PyO3 build + test jobs pass session_runtime_threads_block_sigpipe. Their no-network pytest tests build a real Session against a local HTTP server, which exercises the moved builder.
    • Formatting, Clippy, Unit + doc tests, tls-rustls, Windows linker PDB, and the live v0 E2E surface and v0 TLS (mitmproxy) jobs all pass.
  • The pyo3 live pytest tier skips here, as it does on main (21 passed, 37 skipped in both; e.g. main run 45768020141). The label-gated ADBC live suite wasn't run.
  • Performance is unaffected: the hook adds one pthread_sigmask call per runtime thread start and nothing on the request path.

Additional notes

  • Futures driven by block_on still run on the caller's thread, which keeps the host's mask. Hyper's connection tasks, which do the writes on established connections, run on the hooked workers.
  • pyo3_log runs Python logging handlers on the thread that emits the record. In an app that restored SIG_DFL, a handler on a session worker that writes to a closed pipe now gets BrokenPipeError instead of killing the process, the same effect fix: block SIGPIPE on kernel runtime threads #509 noted for C-ABI log callbacks. Apps that keep Python's default SIG_IGN see no change.
  • Adversarial review: pending.

This pull request and its description were written by Isaac.

@vuanhphung
vuanhphung changed the base branch from main to fix/block-sigpipe-runtime-threads November 27, 2026 02:20
@vuanhphung
vuanhphung force-pushed the fix/block-sigpipe-adbc-pyo3 branch from 3d8ed34 to c73b6d7 Compare November 30, 2026 17:59
@vuanhphung
vuanhphung changed the base branch from fix/block-sigpipe-runtime-threads to main November 30, 2026 18:00
@vuanhphung
vuanhphung marked this pull request as ready for review November 30, 2026 18:01
@vuanhphung
vuanhphung requested a review from a team as a code owner November 30, 2026 18:01

@oss-reviewer-bot oss-reviewer-bot 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

@vuanhphung
vuanhphung marked this pull request as draft November 30, 2026 18:06
@vuanhphung
vuanhphung marked this pull request as ready for review November 30, 2026 18:10

@oss-reviewer-bot oss-reviewer-bot 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

Export the kernel's block_sigpipe_on_current_thread as a #[doc(hidden)]
crate-root item and hook it with on_thread_start on the ADBC driver-owned
runtime and the pyo3 per-session runtime, workers and blocking pools.
Caller-injected ADBC runtimes are left alone. Linux tests check that a
worker and a spawn_blocking thread of each runtime block SIGPIPE.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

@aakash-saravanan-db aakash-saravanan-db 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.

This cleanly extends #509’s protection to the remaining owned runtimes, while preserving host signal policy and runtime shutdown behavior. Non-blocking follow-up: could we add a PyO3 subprocess test with SIGPIPE restored to SIG_DFL and a peer that disconnects during TLS setup? The handshake can run in the caller-polled block_on future, so the worker-mask tests don’t establish coverage for that path.

@oss-reviewer-bot oss-reviewer-bot 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

@vuanhphung
vuanhphung added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 24fff4b Dec 1, 2026
30 of 32 checks passed
@vuanhphung
vuanhphung deleted the fix/block-sigpipe-adbc-pyo3 branch December 1, 2026 04:44
cathleeny added a commit that referenced this pull request Dec 1, 2026
Brings in the SIGPIPE blocking on the ADBC and pyo3 runtimes (#510) and the
ADBC schema metadata fix (#519). No conflicts.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

This branch was successfully deployed

1 active deployment
azure-prod — 1a525ee1 Deployed Dec 1, 2026 by vuanhphung via PyO3 build + test (Python 3.11) #1058
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.

3 participants