Repository navigation
Keep import duckdb from opening a database and fix the default connection race - #680
Merged
Merged
Conversation
evertlammerts
force-pushed
the
fix-import-opens-database
branch
2 times, most recently
from
October 16, 2026 13:41
7524d9d to
8dc7a27
Compare
evertlammerts
force-pushed
the
fix-import-opens-database
branch
from
October 16, 2026 13:43
8dc7a27 to
0436912
Compare
evertlammerts
enabled auto-merge
October 16, 2026 13:52
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.
Fixes #612.
Importing duckdb opened the default in-memory database and started its thread pools, because the DB API NUMBER type object parsed the strings "BIGNUM" and "DECIMAL" at module scope, and parsing a type string without a connection runs on the default connection. Logical types belong to a connection's catalog, so the DB API categories no longer hold type instances at all: STRING, NUMBER, DATETIME and BINARY are sets of type ids, and
column_type == duckdb.NUMBERtests the id of the type a connection's result handed back. Import now starts no thread.Consequences:
DBAPITypeObjecttakes a collection of type ids; itstypeslist is gone.Comparing a column type with a DB API type object, column type on the left, printed a nanobind implicit conversion failure to stderr on every call. A third equality overload handles that operand; every equality result is unchanged.
Removing the import-time connection exposed a pre-existing deadlock: the default connection holder kept its mutex while connecting, and connecting releases the GIL, so two threads whose first
duckdb.sql()created the default connection hung the process (before, onlyduckdb.close()followed by such a race reached it).set_default_connectionracing a reader deadlocked the same way, on 1.5.6 too. The holder now keeps its mutex only around pointer reads and swaps; connecting and destroying happen outside it. A finalizer that fetches the default connection no longer deadlocks when the default is replaced, and once the module's cleanup has run while the interpreter finalizes, the holder neither opens nor keeps a connection, so nothing is left open at exit. A first-use race may briefly open one database per racing thread.