42 Commits

Author SHA1 Message Date
Ivan FB
d05f7f6441
simplify comments and procs 2026-06-05 21:02:31 +02:00
Ivan FB
1667398f07
more appropriate comment for requestRecycle 2026-06-05 18:13:00 +02:00
Ivan FB
007629c254
refactor(pool): rename slots to contexts
The pool's fixed array holds FFIContext objects, so "contexts" names what
it actually stores; "slot" emphasised array positions but the element type
already conveys that. Swept the "slot" vocabulary to "context" across the
pool, context, macro and test prose so the terminology is consistent with
the field name. Also corrected a stale doc reference — pool.releaseSlot
(no such proc on this branch) is now the real mechanism, ctx.unclaim().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 18:06:18 +02:00
Ivan FB
6c4bbe01cd
remove unused param in releaseFFIContext proc in ffi_context_pool.nim 2026-06-05 17:30:22 +02:00
Ivan FB
5f76d1fa5b
docs(macro): clarify ffiDtor recycle teardown comment
The ffiDtor doc still claimed the generated destructor "calls
destroyFFIContext", but it now uses the recycle path. Replaced that line
with a concise note that the slot is recycled for reuse (bounding fd
usage) and that the call is non-blocking — RET_OK once accepted, real
outcome via callback. Switched the example placeholder from Waku to a
generic MyLibObj, and dropped the duplicate inline comment in the body.

Addresses PR #74 review comment r3363200458.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 17:12:06 +02:00
Ivan FB
18946d0593
better ctx lifecycle management 2026-06-04 21:49:36 +02:00
Ivan FB
e433624645
refactor: drop dead clearContext proc
clearContext had no call sites left after the pool refactor split teardown
into stopAndJoinThreads + cleanUpResources / destroyFFIContext. Remove it
and repoint the ThreadExitTimeout doc comment, which still named it, at
stopAndJoinThreads.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 14:53:56 +02:00
Ivan FB
1c99eaa189
fix(pool): park context on destroy to keep fd reuse active
The reuse branch in createFFIContext only fires for a parked slot, and a
slot is only parked by releaseFFIContext. The generated destructor was
still calling destroyFFIContext (full teardown, marks the slot
uninitialised), so the reuse path never triggered and the fd-leak fix was
inert in the generated API.

Switch ffiDtor to releaseFFIContext so the worker and its fds survive the
destroy and get reused on the next create. This is safe because the
framework handles one request at a time: by the time the destructor runs
the worker is idle, not mid-request, so parking cannot race a handler.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 14:53:36 +02:00
Ivan FB
1da81c42da
spawn ci aganist release branches 2026-06-04 12:16:53 +02:00
Ivan FB
c77581b694
fix(pool): reuse parked contexts to stop per-cycle fd leak
destroyFFIContext stopped and joined the worker threads on every release,
and createFFIContext rebuilt them on the next acquire. Each cycle therefore
allocated a fresh worker — 4 ThreadSignalPtr socketpairs + the ffi/watchdog
thread chronos dispatcher kqueues — and never reclaimed the old ones (the
pool deliberately skips closing them, relying on slot reuse that never
actually reused the resources). A consumer that creates and destroys
contexts repeatedly (e.g. nim-sds ReliabilityManager) leaked ~10 fds per
cycle, unbounded.

Make the pool genuinely reuse a slot's worker:

- Track per-slot `initialized`; createFFIContext builds the worker once and
  reuses it on every later acquisition of the same slot.
- Add releaseFFIContext: parks a context (returns its slot) WITHOUT stopping
  the threads, so the next acquire reuses the same fds. It also drops the
  stale C event callback so a watchdog tick on a parked slot cannot invoke a
  callback whose user-data the consumer may already have freed. The caller is
  responsible for quiescing its library object (on the FFI thread) first.
- destroyFFIContext keeps full-teardown semantics for error/non-pooling
  paths and now marks the slot uninitialised so a later acquire rebuilds it.

Tests: add a park & reuse suite (same-slot live-worker reuse, callback/lib
pointer dropped on park, and fd usage bounded across 20 park/reuse cycles).
The fd test fails by ~10 fds/cycle against the pre-fix behaviour. Green
under both --mm:refc and --mm:orc.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 12:07:17 +02:00
Ivan FB
fb25f069d2
add changelog for 0.1.4 v0.1.4 2026-06-02 23:07:06 +02:00
Ivan FB
1285badcaa
create v0.1.4 2026-06-02 22:53:47 +02:00
Ivan FB
6d31fa30bd
use fixed array of ctx to avoid consuming all fds (#14) 2026-05-13 00:02:23 +02:00
Gabriel Cruz
81c62c263e
fix: context buffer overflow (#21) 2026-05-11 19:21:40 -03:00
Ivan FB
a52c4facd9
Simplified FFI authoring with auto-generated C++ and Rust bindings (#15) 2026-05-11 23:28:17 +02:00
Gabriel Cruz
e99eb60fd1
chore: run tests with refc (#20)
* chore: run tests with refc

* chore: split ci jobs

* chore: fix tests
2026-05-09 10:47:37 -03:00
Gabriel Cruz
37d19c0687
chore: remove CatchableError (#19) 2026-05-08 14:14:16 -03:00
Ivan FB
e3eca63236
first ci version (#12) 2026-04-29 23:48:36 +02:00
Ivan FB
df2277e726
Fix memleaks (#11)
* protect against mem leak in case of failures sending requests to ffi thread
* better cleanup if failures in createFFIContext
* avoid dangling cstring in handleRes under ARC/ORC
* better resource cleanup in destroyFFIContext
* invoke onNotResponding if failure in destroyFFIContext
* correct seq copy in alloc
* make sure the lock is init before cleanUpResources
* better possible exception handling in processReq
* guard allocSharedSeq if given seq is empty
* enhance error handling in ffi_context
* add new tests and some corrections
2026-04-27 21:22:45 +02:00
Pablo Lopez
bb8a3e7e22
fix: add install_name for mac (#8)
not to hardcode the paths
2026-02-20 17:37:13 +02:00
Igor Sirotin
c2c03f1f0f
chore: update license files to comply with Logos licensing requirements 2026-02-05 15:12:18 +00:00
Ivan Folgueira Bande
06111de155
properly importing and exporting chronicles v0.1.3 2026-01-23 17:55:43 +01:00
Ivan Folgueira Bande
d3fe7b4389
properly exposing chronicles and tables when importing ffi v0.1.2 2026-01-23 17:34:01 +01:00
Ivan Folgueira Bande
bb8ed28ab0
add require chronicles taskpools and import std tables v0.1.1 2026-01-23 15:01:08 +01:00
Ivan FB
9fff004b19
add explicit timeout when sending watchdog requests (#7) 2026-01-16 15:48:35 +01:00
Darshan
c2cc2d7ea1
identation error (#5) 2026-01-07 00:01:17 +05:30
Ivan Folgueira Bande
d7a5492121
avoid use gc ed types in FFIContext and better macro documentation 2025-12-13 23:53:59 +01:00
Ivan Folgueira Bande
6811c8675f
make registeredRequests no threadvar
This gives better results in logos-messaging-go-bindings
Can be shared across threads because is populated at compile-time
and only read at run-time.
2025-12-12 14:45:59 +01:00
Ivan Folgueira Bande
803744dd29
rm some Waku leftover references 2025-12-11 23:50:00 +01:00
Ivan FB
75251fb721
Merge pull request #1 from logos-messaging/extend-more
Complete first ffi macro definition
2025-12-11 17:26:01 +01:00
Ivan Folgueira Bande
5964e287a9
rm useless comments 2025-12-11 17:21:47 +01:00
Ivan Folgueira Bande
e0cf0c8842
fixes for proper proc exposure to c 2025-12-11 17:11:59 +01:00
Ivan Folgueira Bande
142a57f543
set logger in main thread body 2025-12-11 17:10:24 +01:00
Ivan Folgueira Bande
da3251aa1a
evolving more 2025-12-10 17:43:26 +01:00
Ivan Folgueira Bande
86dc58e7c2
add ffi macro 2025-12-09 18:51:50 +01:00
Ivan Folgueira Bande
b974eab39c
comment echo repr lines 2025-09-17 14:38:01 +02:00
Ivan Folgueira Bande
3c7f7f9a1c
remove comment 2025-09-17 14:37:53 +02:00
Ivan Folgueira Bande
a1a6536b3c
general ffi increments 2025-09-17 14:37:45 +02:00
Ivan Folgueira Bande
356f0ccc1b
working simplification 2025-09-17 14:37:36 +02:00
Ivan Folgueira Bande
46e51e45a6
more positive progress. Getting closer 2025-09-17 14:37:28 +02:00
Ivan Folgueira Bande
bbddf6925b
First commit 2025-09-17 14:37:11 +02:00
Ivan FB
04fd9f0f6d
Initial commit 2025-09-17 14:34:56 +02:00