| 1729 | } |
| 1730 | |
| 1731 | static void runtime_worker_finish(cbm_daemon_runtime_worker_t *worker) { |
| 1732 | cbm_daemon_runtime_service_t *service = worker->service; |
| 1733 | runtime_worker_disconnect(worker); |
| 1734 | if (!runtime_worker_reap_application(worker, true)) { |
| 1735 | /* Fail closed on an impossible/invalid join rather than closing the |
| 1736 | * session or freeing storage a callback could still reference. The |
| 1737 | * service intentionally remains non-terminal for diagnosis. */ |
| 1738 | return; |
| 1739 | } |
| 1740 | if (worker->application_session_opened) { |
| 1741 | service->application.session_close(service->application.context, |
| 1742 | worker->application_session); |
| 1743 | worker->application_session = NULL; |
| 1744 | worker->application_session_opened = false; |
| 1745 | } |
| 1746 | if (worker->connection) { |
| 1747 | /* Off the service mutex: a peer that just received its final response |
| 1748 | * (hello rejection, disconnect acknowledgement) must be able to read |
| 1749 | * it before the handle closes; see cbm_daemon_ipc_connection_drain. */ |
| 1750 | cbm_daemon_ipc_connection_drain(worker->connection, RUNTIME_WORKER_DRAIN_TIMEOUT_MS); |
| 1751 | } |
| 1752 | cbm_mutex_lock(&service->mutex); |
| 1753 | if (worker->connection) { |
| 1754 | cbm_daemon_ipc_connection_close(worker->connection); |
| 1755 | worker->connection = NULL; |
| 1756 | } |
| 1757 | if (service->active_connections > 0) { |
| 1758 | service->active_connections--; |
| 1759 | } |
| 1760 | atomic_store_explicit(&worker->done, true, memory_order_release); |
| 1761 | cbm_mutex_unlock(&service->mutex); |
| 1762 | } |
| 1763 | |
| 1764 | static bool runtime_activation_peer_matches_claim(cbm_daemon_runtime_service_t *service, |
| 1765 | uint64_t process_id, const char *claimed_build) { |
no test coverage detected