| 1148 | } |
| 1149 | |
| 1150 | static void runtime_worker_disconnect(cbm_daemon_runtime_worker_t *worker) { |
| 1151 | cbm_daemon_runtime_service_t *service = worker->service; |
| 1152 | cbm_daemon_client_id_t client_id = CBM_DAEMON_CLIENT_ID_INVALID; |
| 1153 | uint64_t shutdown_deadline = runtime_deadline_after(service->shutdown_timeout_ms); |
| 1154 | atomic_store_explicit(&worker->disconnecting, true, memory_order_release); |
| 1155 | cbm_mutex_lock(&service->mutex); |
| 1156 | if (worker->admitted) { |
| 1157 | client_id = worker->client_id; |
| 1158 | worker->admitted = false; |
| 1159 | } |
| 1160 | if (worker->admission_committed) { |
| 1161 | worker->admission_committed = false; |
| 1162 | if (service->committed_clients > 0) { |
| 1163 | service->committed_clients--; |
| 1164 | } |
| 1165 | if (service->committed_clients == 0 && !service->permanent) { |
| 1166 | /* A HELLO whose application session is still opening is only a |
| 1167 | * provisional coordinator client. It cannot keep the generation |
| 1168 | * alive after the final fully committed frontend disconnects. |
| 1169 | * A permanent generation (`daemon start`) deliberately survives |
| 1170 | * this: only the stop/drain ops or a process kill end it. */ |
| 1171 | runtime_service_begin_stopping_locked(service, shutdown_deadline, false, |
| 1172 | "last_committed_client_disconnected"); |
| 1173 | } |
| 1174 | } |
| 1175 | cbm_mutex_unlock(&service->mutex); |
| 1176 | if (client_id == CBM_DAEMON_CLIENT_ID_INVALID) { |
| 1177 | return; |
| 1178 | } |
| 1179 | (void)cbm_daemon_client_disconnected(service->coordinator, client_id, cbm_now_ms()); |
| 1180 | if (worker->application_session_opened && !worker->application_cancelled) { |
| 1181 | worker->application_cancelled = true; |
| 1182 | service->application.session_cancel(service->application.context, |
| 1183 | worker->application_session); |
| 1184 | } |
| 1185 | if (cbm_daemon_coordinator_state(service->coordinator) == CBM_DAEMON_COORDINATOR_STOPPING) { |
| 1186 | runtime_service_begin_stopping(service, service->shutdown_timeout_ms, false, |
| 1187 | "coordinator_stopping"); |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | static bool runtime_worker_service_running(cbm_daemon_runtime_worker_t *worker) { |
| 1192 | cbm_daemon_runtime_service_t *service = worker->service; |
no test coverage detected