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