Repository navigation
Conversation
…busy Connection.prepare(), create_arrow_table(), create_arrow_rel_table() and drop_arrow_table(), and the pybind connection's get_num_nodes(), get_num_rels() and get_all_edges_for_torch_geometric(), called into the engine with the GIL held. The connection runs one statement at a time, so while another thread scanned a DataFrame on the same connection the call waited for that statement, and the scan waited for the GIL to read the DataFrame. Both threads, and every other Python thread, blocked forever. These bindings now release the GIL around the engine calls only, as execute() and query() already do. Like execute(), each first pins the connection state, so a close() from another thread during the wait cannot free it; that is why the release is in the body and not a call_guard. The parameters, Arrow tables and the numpy buffer are read before the release, and the keep-alive references are stored after the GIL is taken back. Scans and Python UDFs that run while a statement is compiled take the GIL themselves, as they do under query(). get_all_edges_for_torch_geometric() runs one statement per batch, so relationships committed by another connection during the fetch made it write past the numpy array. It now checks the array size against the relationship count and raises if the batches return more edges than were counted. It sets one thread before every batch, since another thread can now change the setting in between, and restores it when it raises. The three torch-geometric methods share one StorageDriver context per connection, which runs BEGIN, a read and COMMIT as separate statements; the GIL kept two threads out of it, so the calls now take a per-connection mutex. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opening a default-size in-memory database inside the pytest process fails
on the C-API CI runner ("Buffer manager exception: Mmap for size
8796093022208 failed."), so the six pybind-only tests failed there
instead of skipping. The backend check now uses lazy_init, as conftest
does, and the edge-array test uses the conn_db_in_mem fixture.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Defer to 0.24.x cycle |
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.
This work was produced with the help of language models.
Connection.prepare()hung forever if another thread scanned a DataFrame on the same connection, and so didcreate_arrow_table(),create_arrow_rel_table(),drop_arrow_table(),get_num_nodes(),get_num_rels()andget_all_edges_for_torch_geometric(). Each waited for the scan while holding the GIL, which the scan needs to read the DataFrame. This affects the pybind backend on 0.21.2 through 0.23.0.Fix. These calls now release the GIL around the engine call only and, like
execute(), pin the connection state first, so aclose()during the wait cannot free it; that is why the release is in the body and not acall_guard. The three torch-geometric methods share one storage context per connection, which runsBEGIN, a read andCOMMITas separate statements, so they now take a per-connection mutex.get_all_edges_for_torch_geometric()wrote past the numpy array when another connection added relationships during the fetch; onmainthat aborts with heap corruption. It now raises instead, sets one thread before every batch, and restores the setting if it raises.Depends on LadybugDB/ladybug#1718. A statement destroyed on one thread races another thread's execute on the same connection, and without the deadlock a
prepare()loop beside a DataFrame scan hits it: 4 of 150 runs crashed on enginemain, none of 150 with #1718. Theprepare()test keeps its statements until the scan stops; the torch-geometric case drops one per call and can crash on enginemainuntil #1718 is merged.Tests.
test_call_does_not_block_a_dataframe_scanruns each call above, a failing create and a CSR relationship table for 2 seconds beside a DataFrame scan, in a subprocess with a 60-second timeout. All eight cases deadlock on pybind onmainand 0.23.0; the five that also run on the C-API backend pass there. Three more tests cover a too-small edge array, an edge fetch while another connection inserts (aborts onmain), and both counts from two threads on one connection (crashed without the mutex). Full suites on Python 3.12: no new failures on either backend.Fixes #85