Skip to content

fix(settings): validate DUCKDB_THREADS instead of silently producing NaN - #5130

Open
pedrofrxncx wants to merge 1 commit into
mainfrom
fix/validate-duckdb-threads-env-var
Open

fix(settings): validate DUCKDB_THREADS instead of silently producing NaN#5130
pedrofrxncx wants to merge 1 commit into
mainfrom
fix/validate-duckdb-threads-env-var

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Bug (same class as PORT/DATABASE_POOL_MAX, this tick's other session): resolveConfig parsed DUCKDB_THREADS as envVars.DUCKDB_THREADS ? Number(envVars.DUCKDB_THREADS) : undefined — unlike CLICKHOUSE_MAX_MEMORY_USAGE (which falls back to undefined via || undefined), an invalid value here (e.g. DUCKDB_THREADS=abc) produces NaN, which is then threaded into DuckDBTuning.threads and stringified into the DuckDB instance threads config (apps/mesh/src/monitoring/query-engine.ts), causing a cryptic runtime failure when the embedded monitoring DuckDB engine spins up instead of a clear startup error.

A maintainer wants this because it turns a silent/cryptic monitoring-engine failure into a clear fail-fast error at config-resolution time, matching the validation already applied to PORT and DATABASE_POOL_MAX.

Fix: added toPositiveIntegerOrUndefined (same shape as the existing toPositiveIntegerOrDefault but with no default, since DuckDB threads legitimately has no numeric default — unset means "use all CPUs") and used it for DUCKDB_THREADS. Throws "DUCKDB_THREADS must be a positive integer" for non-integer/non-positive values, same as the sibling validators.

Regression test: added a describe("resolveConfig duckdb threads") block to resolve-config.test.ts covering the unset-default, valid-value, and invalid-value-throws cases (mirroring the existing DATABASE_POOL_MAX/NATS_TUNNEL_SESSION_TTL_SECONDS test blocks).

Reviewer check: bun test apps/mesh/src/settings/resolve-config.test.ts

Locally ran: bun run fmt, cd apps/mesh && bunx tsc --noEmit, and the targeted test file above (all green). Full CI validates the rest.


Summary by cubic

Validate DUCKDB_THREADS during config resolution to fail fast on invalid values, preventing NaN from reaching DuckDB and causing a cryptic startup crash in the monitoring engine.

  • Bug Fixes
    • Added toPositiveIntegerOrUndefined and used it for DUCKDB_THREADS; invalid values throw "DUCKDB_THREADS must be a positive integer", unset stays undefined (use all CPUs).
    • Added tests for unset, valid, and invalid cases in apps/mesh/src/settings/resolve-config.test.ts.

Written for commit 9bd1d79. Summary will update on new commits.

Review in cubic

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.

1 participant