Repository navigation
Description
Summary
#326 gave the C-ABI Tokio runtime an explicit thread_stack_size(2 MiB). The value is
fixed, not a floor, so it also shrinks worker stacks for any host whose ambient
RUST_MIN_STACK is larger than 2 MiB — the opposite of the change's stated intent.
From the merged code (src/c_abi/mod.rs):
// Native consumers may set that variable for their own thread pools; keep it
// from shrinking the kernel-owned workers below Tokio's supported default.
const C_ABI_RUNTIME_THREAD_STACK_SIZE: usize = 2 * 1024 * 1024;
...
.thread_stack_size(C_ABI_RUNTIME_THREAD_STACK_SIZE)The comment says the goal is to stop RUST_MIN_STACK from shrinking the workers. But
because thread_stack_size is absolute, a host that deliberately asked for more than
2 MiB now gets less.
Measured
An explicit stack_size makes std::thread ignore RUST_MIN_STACK entirely. Two Rust
std threads under RUST_MIN_STACK=3194880, stack bounds read with
pthread_getattr_np via an LD_PRELOAD interposer:
| thread | resulting stack |
|---|---|
default stack_size (honours RUST_MIN_STACK) |
3120 KB |
explicit stack_size(2 MiB) (what #326 forces) |
2048 KB |
Why it matters concretely
A databricks-odbc 0.4.0 partner's process has RUST_MIN_STACK=3194880
(= ulimit -s 3120 × 1024), so its kernel-c-abi workers are 3120 KiB today — confirmed
byte-for-byte against three of their core dumps. Once the ODBC driver bumps
KERNEL_REPO_TAG past #326, those workers become 2048 KiB: a 34% reduction for a
process that is already being investigated for a stack-related SIGSEGV on the connect
path. Reducing available stack is the wrong direction there.
(The ODBC driver currently pins 9ecd357, which predates #326, so nothing is affected
until that pin moves — this is a pre-emptive fix, not a live regression.)
Proposed fix — make 2 MiB a floor, not a cap
// 2 MiB is a FLOOR, not a cap: clamp a too-small ambient RUST_MIN_STACK up to
// Tokio/std's normal default, without overriding a host that deliberately asked
// for more.
let stack = std::env::var("RUST_MIN_STACK")
.ok()
.and_then(|v| v.parse::<usize>().ok())
.unwrap_or(0)
.max(C_ABI_RUNTIME_THREAD_STACK_SIZE);This preserves the whole point of #326 (a 16 KiB RUST_MIN_STACK still gets clamped up to
2 MiB) while never shrinking anyone.
Test coverage
c_abi_runtime_ignores_ambient_rust_min_stack sets RUST_MIN_STACK=16384 and asserts the
HTTP client builds; that still passes with a floor. Worth adding the missing direction: a
case with RUST_MIN_STACK above 2 MiB asserting the larger value is preserved — the
behaviour this issue is about is currently untested.
Notes
Measured peak worker stack usage for a real SQLDriverConnect + SELECT 1 + fetch is
~67 KiB (via a stack-painting LD_PRELOAD interposer), so 2 MiB has ~30x headroom and
neither value is dangerous in normal operation. This is about not silently overriding an
embedder's explicit choice.
Activity
oss-engineer-bot commentedon Sep 9, 2026
🤖 engineer-bot opened a fix PR: #329
Review before merge.