Skip to content

Commit 7ef55e8

Browse files
committed
fix: test failures
1 parent 2cde738 commit 7ef55e8

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src_py/prepared_statement.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ def __init__(
3333
self._prepared_statement = connection._connection.prepare(query, parameters)
3434
self._connection = connection
3535

36+
def close(self) -> None:
37+
"""
38+
Release the underlying C-API prepared statement resources.
39+
40+
The C-API ``PreparedStatement`` (from ``_lbug_capi.py``) holds a
41+
``lbug_prepared_statement`` C struct that must be destroyed explicitly;
42+
it is NOT garbage-collected when the Python wrapper is dropped.
43+
The pybind variant is managed by ``shared_ptr`` and can be dropped
44+
without an explicit call.
45+
46+
``Connection.close()`` iterates the implicit prepared-statement cache
47+
and calls this method on every cached entry so that resources are
48+
freed when the connection is closed.
49+
"""
50+
close_fn = getattr(self._prepared_statement, "close", None)
51+
if callable(close_fn):
52+
close_fn()
53+
54+
def __del__(self) -> None:
55+
self.close()
56+
3657
def is_success(self) -> bool:
3758
"""
3859
Check if the prepared statement is successfully prepared.

test/test_pybind_implicit_prepare_cache_threading.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
)
3636
def test_shared_connection_concurrent_same_query(num_threads: int, iters: int) -> None:
3737
"""Many threads on a single connection must each see its own bound value."""
38-
db = lb.Database(":memory:", buffer_pool_size=2**28)
38+
# Use an explicit max_db_size (1 GB) so the C-API backend does not default
39+
# to the library's 8 TB mmap region, which fails on CI runners with tight
40+
# virtual-address limits.
41+
db = lb.Database(":memory:", buffer_pool_size=2**28, max_db_size=2**30)
3942
conn = lb.Connection(db)
4043

4144
errors: list[tuple[int, list]] = []

0 commit comments

Comments
 (0)