8000 fix(duckdb_pool): apply MINILAKE_DUCKDB_MEMORY_LIMIT to every DuckDB connection by avison9 · Pull Request #68 · dmux/minilake · GitHub
[go: up one dir, main page]

Skip to content
8000

fix(duckdb_pool): apply MINILAKE_DUCKDB_MEMORY_LIMIT to every DuckDB connection - #68

Merged
dmux merged 2 commits into
dmux:mainfrom
avison9:fix/duckdb-memory-limit-51
Oct 27, 2026
Merged

dmux merged 2 commits into
dmux:mainfrom
avison9:fix/duckdb-memory-limit-51

Conversation

@avison9
@avison9 avison9 commented Oct 26, 2026 •
Copy link
Copy Markdown
Contributor

Closes #51

Summary

MINILAKE_DUCKDB_MEMORY_LIMIT is documented as the way to cap DuckDB's memory (default 4GB),
but it was parsed into settings.duckdb_memory_limit and never passed to any connection. Every
DuckDB database therefore ran with DuckDB's own default of 80% of host RAM, so users relying on
the setting to keep minilake inside a CI runner or a memory-limited container had no protection.

Before / after

MINILAKE_DUCKDB_MEMORY_LIMIT=16MB uv run minilake --port 8000
from databricks.sdk import WorkspaceClient

w = WorkspaceClient(host="http://localhost:8000", token="x")
wh = w.warehouses.create(name="wh")
r = w.statement_execution.execute_statement(
    warehouse_id=wh.id, statement="SELECT current_setting('memory_limit')"
)
print(r.result.data_array[0][0])

# BEFORE: 24.8 GiB   <- 80% of host RAM, the 16MB setting is ignored
# AFTER:  15.2 MiB   <- 16MB, shown by DuckDB in binary units

Root cause

DuckDBPool._connect_config() builds the config= for both duckdb.connect calls (the shared
Unity Catalog connection and each warehouse connection), and it only ever carried the extension
directory settings, so memory_limit never reached DuckDB.

What changed

  • DuckDBPool.__init__ takes an optional memory_limit, falling back to
    settings.duckdb_memory_limit, mirroring the existing extension_dir parameter.
  • _connect_config() always includes memory_limit. Both connection paths already go through it,
    so one change covers both.
  • An invalid value (e.g. lots) makes duckdb.connect raise. The UC connection is opened during
    startup, so a bad setting now stops the server instead of being silently ignored. No separate
    validation was added, so DuckDB's own parser stays the single source of truth.
  • docs/configuration.md no longer describes the setting as a no-op, and notes that the limit
    applies per database (the shared UC database and each warehouse database each get their own).

Passing the limit through config= was chosen over SET memory_limit after connecting: it is
at 8000 omic (no window where the connection runs unlimited) and reuses the existing helper.

Testing

Full suite via docker-compose.test.yml, image rebuilt:

  • Before: 406 passed, 0 failed, 0 skipped
  • After: 409 passed, 0 failed, 0 skipped (the 3 new tests)
  • ruff check, ruff format --check and pre-commit hooks clean

New tests in tests/test_duckdb_memory_limit.py:

  • test_statement_execution_uses_configured_memory_limit: via the real databricks-sdk, the
    engine's current_setting('memory_limit') matches the configured value.
  • test_every_pool_connection_gets_the_memory_limit: both the UC connection and a warehouse
    connection apply a custom limit (statements run on the UC connection, so the SDK test alone
    would not cover warehouse connections).
  • test_invalid_memory_limit_fails_loudly: a malformed limit raises on connect.

Risk / rollout

The documented 4GB default now actually takes effect, which lowers the effective cap on hosts
with more than ~5 GB of RAM. DuckDB spills large operators to disk, so most heavy queries slow
down rather than fail, but a query needing more than 4GB of non-spillable memory will now raise
an out-of-memory error where it previously succeeded. Raising MINILAKE_DUCKDB_MEMORY_LIMIT
restores the old headroom. Probably worth a line in the release notes.

…connection

The setting was parsed but never passed to duckdb.connect, so every
database ran with DuckDB's default of 80% of host RAM. Pass memory_limit
through _connect_config, which both the Unity Catalog and warehouse
connections use. An invalid value now fails at startup instead of being
ignored.

Closes dmux#51
@avison9 avison9 changed the title fix(duckdb_pool): apply MINILAKE_DUCKDB_MEMORY_LIMIT to every DuckDB … fix(duckdb_pool): apply MINILAKE_DUCKDB_MEMORY_LIMIT to every DuckDB connection Oct 26, 2026
@dmux dmux self-assigned this Oct 26, 2026
@dmux dmux added the bug Something isn't working label Oct 26, 2026
@dmux
dmux merged commit b3d3aae into dmux:main Oct 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MINILAKE_DUCKDB_MEMORY_LIMIT is never applied to DuckDB

2 participants

0