Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED] microservice cleanup (flapping MicroServiceStops... tests) #816

Merged
merged 14 commits into from
Nov 5, 2024
Merged
2 changes: 1 addition & 1 deletion examples/micro-sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static microError *handle_sequence(microRequest *req)
result_len = snprintf(result, sizeof(result), "%Lf", value);
if (err == NULL)
err = microRequest_Respond(req, result, result_len);

microArgs_Destroy(args);
return err;
}
Expand Down
4 changes: 4 additions & 0 deletions src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ _freeConn(natsConnection *nc)
natsStrHash_Destroy(nc->respMap);
natsCondition_Destroy(nc->reconnectCond);
natsMutex_Destroy(nc->subsMu);
natsMutex_Destroy(nc->servicesMu);
natsMutex_Destroy(nc->mu);
NATS_FREE(nc->services);

NATS_FREE(nc);

Expand Down Expand Up @@ -3238,6 +3240,8 @@ natsConn_create(natsConnection **newConn, natsOptions *options)
s = natsMutex_Create(&(nc->mu));
if (s == NATS_OK)
s = natsMutex_Create(&(nc->subsMu));
if (s == NATS_OK)
s = natsMutex_Create(&(nc->servicesMu));
if (s == NATS_OK)
s = _setupServerPool(nc);
if (s == NATS_OK)
Expand Down
41 changes: 0 additions & 41 deletions src/glib/glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ _freeLib(void)
nats_freeDispatcherPool(&gLib.replyDispatchers);

natsNUID_free();
natsMutex_Destroy(gLib.service_callback_mu);
natsHash_Destroy(gLib.all_services_to_callback);

natsCondition_Destroy(gLib.cond);

Expand Down Expand Up @@ -290,11 +288,6 @@ nats_openLib(natsClientConfig *config)
if (s == NATS_OK)
s = nats_initDispatcherPool(&(gLib.replyDispatchers), config->ReplyThreadPoolMax);

if (s == NATS_OK)
s = natsMutex_Create(&gLib.service_callback_mu);
if (s == NATS_OK)
s = natsHash_Create(&gLib.all_services_to_callback, 8);

if (s == NATS_OK)
gLib.initialized = true;

Expand Down Expand Up @@ -443,40 +436,6 @@ void nats_ReleaseThreadMemory(void)
natsMutex_Unlock(gLib.lock);
}

natsStatus
natsLib_startServiceCallbacks(microService *m)
{
natsStatus s;

natsMutex_Lock(gLib.service_callback_mu);
s = natsHash_Set(gLib.all_services_to_callback, (int64_t)m, (void *)m, NULL);
natsMutex_Unlock(gLib.service_callback_mu);

return NATS_UPDATE_ERR_STACK(s);
}

void natsLib_stopServiceCallbacks(microService *m)
{
if (m == NULL)
return;

natsMutex_Lock(gLib.service_callback_mu);
natsHash_Remove(gLib.all_services_to_callback, (int64_t)m);
natsMutex_Unlock(gLib.service_callback_mu);
}

natsMutex *
natsLib_getServiceCallbackMutex(void)
{
return gLib.service_callback_mu;
}

natsHash *
natsLib_getAllServicesToCallback(void)
{
return gLib.all_services_to_callback;
}

natsClientConfig *nats_testInspectClientConfig(void)
{
// Immutable after startup
Expand Down
5 changes: 0 additions & 5 deletions src/glib/glibp.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ typedef struct __natsLib

natsGCList gc;

// For micro services code
natsMutex *service_callback_mu;
// uses `microService*` as the key and the value.
natsHash *all_services_to_callback;

} natsLib;

natsLib *nats_lib(void);
Expand Down
Loading