MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / runtime_worker_disconnect

Function runtime_worker_disconnect

src/daemon/runtime.c:1119–1158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1117}
1118
1119static void runtime_worker_disconnect(cbm_daemon_runtime_worker_t *worker) {
1120 cbm_daemon_runtime_service_t *service = worker->service;
1121 cbm_daemon_client_id_t client_id = CBM_DAEMON_CLIENT_ID_INVALID;
1122 uint64_t shutdown_deadline = runtime_deadline_after(service->shutdown_timeout_ms);
1123 atomic_store_explicit(&worker->disconnecting, true, memory_order_release);
1124 cbm_mutex_lock(&service->mutex);
1125 if (worker->admitted) {
1126 client_id = worker->client_id;
1127 worker->admitted = false;
1128 }
1129 if (worker->admission_committed) {
1130 worker->admission_committed = false;
1131 if (service->committed_clients > 0) {
1132 service->committed_clients--;
1133 }
1134 if (service->committed_clients == 0 && !service->permanent) {
1135 /* A HELLO whose application session is still opening is only a
1136 * provisional coordinator client. It cannot keep the generation
1137 * alive after the final fully committed frontend disconnects.
1138 * A permanent generation (`daemon start`) deliberately survives
1139 * this: only the stop/drain ops or a process kill end it. */
1140 runtime_service_begin_stopping_locked(service, shutdown_deadline, false,
1141 "last_committed_client_disconnected");
1142 }
1143 }
1144 cbm_mutex_unlock(&service->mutex);
1145 if (client_id == CBM_DAEMON_CLIENT_ID_INVALID) {
1146 return;
1147 }
1148 (void)cbm_daemon_client_disconnected(service->coordinator, client_id, cbm_now_ms());
1149 if (worker->application_session_opened && !worker->application_cancelled) {
1150 worker->application_cancelled = true;
1151 service->application.session_cancel(service->application.context,
1152 worker->application_session);
1153 }
1154 if (cbm_daemon_coordinator_state(service->coordinator) == CBM_DAEMON_COORDINATOR_STOPPING) {
1155 runtime_service_begin_stopping(service, service->shutdown_timeout_ms, false,
1156 "coordinator_stopping");
1157 }
1158}
1159
1160static bool runtime_worker_service_running(cbm_daemon_runtime_worker_t *worker) {
1161 cbm_daemon_runtime_service_t *service = worker->service;

Calls 8

runtime_deadline_afterFunction · 0.85
cbm_mutex_lockFunction · 0.85
cbm_mutex_unlockFunction · 0.85
cbm_now_msFunction · 0.85

Tested by

no test coverage detected