From f07ef745009817e6944583f6116d93d83354d71c Mon Sep 17 00:00:00 2001 From: Ivan FB Date: Sun, 7 Jun 2026 19:25:48 +0200 Subject: [PATCH] better guard to avoid double-recycle requests --- ffi/ffi_context.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ffi/ffi_context.nim b/ffi/ffi_context.nim index cc9130f..729d9a4 100644 --- a/ffi/ffi_context.nim +++ b/ffi/ffi_context.nim @@ -471,10 +471,14 @@ proc requestRecycle*[T]( ## ## During recycling, the FFI thread drains the handlers, frees the lib and releases ## the context, then fires `callback` (RET_OK drained, RET_ERR stuck). - ctx.recycleCallback = callback - ctx.recycleUserData = userData ctx.lock.acquire() + if ctx.lifecycle.load() != CtxLifecycle.Active: + ctx.lock.release() + return err("requestRecycle: context is not Active (already recycling)") + + ctx.recycleCallback = callback + ctx.recycleUserData = userData ctx.lifecycle.store(CtxLifecycle.RecyclePending) ctx.lock.release()