Skip to content

Commit 0af1225

Browse files
tae898claude
andcommitted
Native: AsyncExecutor.transaction releases its callbacks once the executor has finished its work
AsyncExecutor.transaction registers up to three callbacks per call (block, ok, error). They are kept in the executor's _cb_ids (declared, never used so far) and forgotten when wait_completion has returned or the executor is closed, because a retry calls the block again. The other async operations still register callbacks that are never released; that is unchanged. The reply of a failing block needs nothing new here: with #67 it is written into the out slot as library memory, which outlives the Python thread state of an async writer, so the Java side reads {"error": ...} and the writer rolls back and reaches the error callback. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent a815a57 commit 0af1225

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/arcadedb/_native/extras.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,18 @@ def run(message):
713713
args["ok"] = _register(lambda message: ok_callback())
714714
if error_callback is not None:
715715
args["err"] = self._error_callback(error_callback)
716+
# a retry calls the block again, so the callbacks live until the executor has finished its work (wait_completion, close)
717+
self._cb_ids.extend(v for k, v in args.items() if k in ("cb", "ok", "err"))
716718
if slot is not None:
717719
args["slot"] = int(slot)
718720
self._op("transaction", **args)
719721

722+
def _release_callbacks(self):
723+
"""Forget the callbacks of the finished ``transaction`` calls."""
724+
ids, self._cb_ids = self._cb_ids, []
725+
for cid in ids:
726+
_forget(cid)
727+
720728
def wait_completion(self, timeout_ms: Optional[int] = None):
721729
if timeout_ms is None:
722730
self._op("wait")
@@ -729,6 +737,7 @@ def wait_completion(self, timeout_ms: Optional[int] = None):
729737
raise TimeoutError(
730738
f"Async operations did not complete within {timeout_ms}ms"
731739
)
740+
self._release_callbacks() # nothing is pending any more
732741

733742
def on_ok(self, callback: Callable[[], None]):
734743
self._op("on_ok", cb=_register(lambda message: callback()))
@@ -745,6 +754,7 @@ def close(self):
745754
self._op("close")
746755
finally:
747756
self._closed = True
757+
self._release_callbacks()
748758
owner, self._owner = self._owner, None
749759
if owner is not None:
750760
owner._discard_async_executor(self)

0 commit comments

Comments
 (0)