Repository navigation
fix(duckdb): keep DuckDB's expression recursion within the stacks it runs on - #4293
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
max_expression_depthto 250, so DuckDB refuses a deeper statement with its own Parser or Binder error instead of overflowing a stack. A CHECK about 575 deep crashed the app on macOS when any table's keys were read:duckdb_constraints()binds every CHECK on DuckDB's own worker threads, which get 512 KiB there.on_duckdb_stack), the stack DuckDB's CLI has, so the open's unguarded catalog read no longer overflows the runtime's 2 MiB blocking thread. The app's own connections pin the limit per session, so an editor tab'sSET GLOBALdoes not reach them.DuckDBStackExecutor, shared by both apps), so an open, an ATTACH or a close of a deep file no longer overflows a 512 KiB cooperative or dispatch thread. The macOS isolated import opens and closes its file on that stack.core.ymlruns the new DuckDB depth tests on Windows x64, Windows Arm64 and macOS, where DuckDB's threads get other stacks than on Linux.external_threads) and what stays DuckDB's: a file built past DuckDB's own limit can still overflow DuckDB's threads where it prints or saves expressions.Test plan
deep_expressionstest target, whichcore.ymlalso runs on Windows and macOS:a_file_as_deep_as_duckdb_allows_is_read_or_refused: a CHECK, DEFAULT, generated column, view and macro 992 deep (DuckDB's own deepest); reads are refused at the limit. Fails on main.a_file_deeper_than_a_runtime_thread_holds_opens: a CHECK 3,000 deep opens; on main the open dies with SIGILL.the_limit_holds_on_every_connection_after_a_tab_raises_it: an editor tab and the workspace refuse 250 levels, the workspace also after the tab'sSET GLOBAL; fails without the session pin.DuckDBDeepExpressionTests: a CHECK 900 deep opens and reading its keys fails at the limit; an ATTACH of it reads its catalog.verify.sh core tablepro-driver-duckdb(the 2 macOS-only procfs and/privatepath cases fail on main too),plugins,ios,lint.