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

Function runtime_worker_reap_application

src/daemon/runtime.c:1582–1628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1580}
1581
1582static bool runtime_worker_reap_application(cbm_daemon_runtime_worker_t *worker, bool wait) {
1583 if (!worker->application_thread_started) {
1584 return true;
1585 }
1586 if (!wait && !atomic_load_explicit(&worker->application_thread_done, memory_order_acquire)) {
1587 return false;
1588 }
1589 if (!atomic_load_explicit(&worker->application_thread_done, memory_order_acquire)) {
1590 /* The peer is gone and session_cancel already ran, so the handler owes
1591 * a prompt return; only a handler that ignores cancellation reaches
1592 * the ceiling. An unbounded join here once turned one wedged request
1593 * into a whole-daemon zombie (2026-08-29): the disconnect path
1594 * blocked, the worker slot never released, and the dead generation
1595 * held the endpoint pipes and UI port for nine hours with nothing
1596 * logged while every new client timed out bare. Containment
1597 * terminates the process instead — the kernel releases every native
1598 * claim and the next client starts a fresh generation. */
1599 uint32_t timeout_ms = RUNTIME_ABANDONED_REQUEST_JOIN_TIMEOUT_MS;
1600#ifdef CBM_ENABLE_TEST_SEAMS
1601 uint32_t seam_timeout = atomic_load(&runtime_abandoned_request_join_timeout_seam);
1602 if (seam_timeout != 0) {
1603 timeout_ms = seam_timeout;
1604 }
1605#endif
1606 uint64_t deadline = runtime_deadline_after(timeout_ms);
1607 while (!atomic_load_explicit(&worker->application_thread_done, memory_order_acquire)) {
1608 if (cbm_now_ms() >= deadline) {
1609 /* Terminal in production. A test containment hook returns, and
1610 * the join then waits for the harness to release the handler
1611 * so teardown stays leak-free under the sanitizers. */
1612 runtime_contain_unresponsive_application(worker);
1613 deadline = UINT64_MAX;
1614 }
1615 runtime_wait_tick(deadline);
1616 }
1617 }
1618 if (cbm_thread_join(&worker->application_thread) != 0) {
1619 return false;
1620 }
1621 worker->application_thread_started = false;
1622 free(worker->application_request);
1623 worker->application_request = NULL;
1624 worker->application_request_length = 0;
1625 worker->application_request_token = CBM_DAEMON_RUNTIME_APPLICATION_TOKEN_INVALID;
1626 atomic_store_explicit(&worker->application_thread_done, false, memory_order_release);
1627 return true;
1628}
1629
1630static bool runtime_worker_handle_application(cbm_daemon_runtime_worker_t *worker,
1631 const uint8_t *payload, uint32_t length) {

Callers 2

runtime_worker_finishFunction · 0.85

Calls 5

runtime_deadline_afterFunction · 0.85
cbm_now_msFunction · 0.85
runtime_wait_tickFunction · 0.85
cbm_thread_joinFunction · 0.85

Tested by

no test coverage detected