From 4c9a56606ce1cc1ee11ac3ad2effcd7beea9bb2e Mon Sep 17 00:00:00 2001 From: Lev Brouk Date: Wed, 30 Oct 2024 16:14:15 -0700 Subject: [PATCH] wip ++4 --- src/micro.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/micro.c b/src/micro.c index b12a5c1d..852ffae6 100644 --- a/src/micro.c +++ b/src/micro.c @@ -285,6 +285,7 @@ void micro_release_endpoint_when_unsubscribed(void *closure) microEndpoint *ep = (microEndpoint *)closure; microService *m = NULL; natsSubscription *sub = NULL; + natsConnection *nc = NULL; microDoneHandler doneHandler = NULL; int refs = 0; @@ -307,23 +308,27 @@ void micro_release_endpoint_when_unsubscribed(void *closure) // If this is the last endpoint, we need to notify the service's done // callback. _lock_service(m); + + m->numEndpoints--; + // <>/<> TODO Remove ep from m's list + if (refs == 0) micro_free_endpoint(ep); - m->numEndpoints--; if (m->numEndpoints == 0) { m->stopped = true; doneHandler = m->cfg->DoneHandler; } refs = m->refs; + nc = m->nc; _unlock_service(m); if (doneHandler != NULL) { printf("<>/<> micro_release_endpoint_when_unsubscribed %s last in service, DONE\n", sub->subject); doneHandler(m); - natsConn_removeService(m->nc, m); + natsConn_removeService(nc, m); if (refs == 0) _free_service(m);