better guard to avoid double-recycle requests

This commit is contained in:
Ivan FB 2026-06-07 19:25:48 +02:00
parent c749d890ab
commit f07ef74500
No known key found for this signature in database
GPG Key ID: DF0C67A04C543270

View File

@ -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()