Skip to content

fix(compiler): cap DuckDB threads so a cgroup-capped instance doesn't OOM at boot#42

Merged
lukaisailovic merged 1 commit into
mainfrom
fix/duckdb-thread-cap
Jun 26, 2026
Merged

fix(compiler): cap DuckDB threads so a cgroup-capped instance doesn't OOM at boot#42
lukaisailovic merged 1 commit into
mainfrom
fix/duckdb-thread-cap

Conversation

@lukaisailovic

Copy link
Copy Markdown
Owner

What

Follow-up to #41. With the `.tmp` spill bug fixed, the NAS container exposed a second, distinct failure at boot validation:

```
dataset 'macro_breakdown_today': Out of Memory Error: failed to pin block of
size 256.0 KiB (819.0 MiB/819.1 MiB used)
```

Root cause

DuckDB honors the memory cgroup (auto `memory_limit` ≈ 80% of the 1 GB container = 819 MiB) but scales its thread count to the host core count, ignoring the (absent) CPU cgroup. On a 12-core host that's 12 threads sharing 819 MiB ≈ 68 MiB/thread — below DuckDB's recommended ~125 MiB/thread floor — so the buffer manager can't pin blocks and OOMs at boot. The data is tiny (~5 MB); this is purely a thread-count vs. memory-cap mismatch, not data volume.

Fix

Pin `threads: "4"` in `createInMemoryDuckDB()` so every in-memory instance stays within a cgroup-capped budget regardless of host core count (>125 MiB/thread at 819 MiB; DuckDB clamps to core count on smaller boxes). `memory_limit` is left to DuckDB's correct cgroup-aware default.

Test

Added a guard in `writers.test.ts` asserting `threads=4` and a writable `temp_directory`. `pnpm build && pnpm typecheck && pnpm test && pnpm lint` all pass.

… OOM at boot

DuckDB honors the memory cgroup (memory_limit ~= 80% of the container limit)
but scales its thread count to the HOST core count, ignoring the CPU cgroup.
In a 1 GB container on a 12-core host that's 12 threads sharing an 819 MiB
cap (~68 MiB/thread, below DuckDB's ~125 MiB/thread floor), which OOMs at
boot validation: 'failed to pin block of size 256.0 KiB'. Pin threads to 4
in createInMemoryDuckDB so every instance stays within the cap regardless of
host core count.
@lukaisailovic lukaisailovic merged commit b8a0b7e into main Jun 26, 2026
2 checks passed
@lukaisailovic lukaisailovic deleted the fix/duckdb-thread-cap branch June 26, 2026 17:43
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