| 1518 | } |
| 1519 | |
| 1520 | static void *runtime_application_worker(void *opaque) { |
| 1521 | cbm_daemon_runtime_worker_t *worker = opaque; |
| 1522 | cbm_daemon_runtime_service_t *service = worker->service; |
| 1523 | uint8_t *response = NULL; |
| 1524 | uint32_t response_length = 0; |
| 1525 | cbm_daemon_runtime_application_status_t status = service->application.request( |
| 1526 | service->application.context, worker->application_session, |
| 1527 | worker->application_request_token, worker->application_request, |
| 1528 | worker->application_request_length, &response, &response_length); |
| 1529 | |
| 1530 | bool valid_status = runtime_application_status_is_callback_result(status); |
| 1531 | bool valid_response = |
| 1532 | response_length <= CBM_DAEMON_RUNTIME_APPLICATION_PAYLOAD_MAX && |
| 1533 | (response_length == 0 || response != NULL) && |
| 1534 | (status == CBM_DAEMON_RUNTIME_APPLICATION_OK || (response == NULL && response_length == 0)); |
| 1535 | if (!valid_status || !valid_response) { |
| 1536 | free(response); |
| 1537 | response = NULL; |
| 1538 | response_length = 0; |
| 1539 | status = CBM_DAEMON_RUNTIME_APPLICATION_HANDLER_ERROR; |
| 1540 | } |
| 1541 | |
| 1542 | /* Completion must be one atomic transition from the client's point of |
| 1543 | * view: publish the done flag BEFORE the response bytes leave, so by the |
| 1544 | * time any client can react to the response, admission already observes |
| 1545 | * this slot as reusable. With the store after the send, a client that |
| 1546 | * pipelines its next request the moment it sees a response raced this |
| 1547 | * thread's final instructions and was rejected BUSY — on loaded Windows |
| 1548 | * hosts roughly half of all back-to-back requests on one connection, |
| 1549 | * surfacing as the wandering Phase 5 session drops. The admission side |
| 1550 | * joins this thread after observing the flag, which safely absorbs the |
| 1551 | * tail of the send. */ |
| 1552 | atomic_store_explicit(&worker->application_thread_done, true, memory_order_release); |
| 1553 | bool sent = runtime_worker_send_application_response(worker, worker->application_request_token, |
| 1554 | status, response, response_length, true); |
| 1555 | free(response); |
| 1556 | if (!sent && !atomic_load_explicit(&worker->disconnecting, memory_order_acquire)) { |
| 1557 | cbm_daemon_ipc_connection_interrupt(worker->connection); |
| 1558 | } |
| 1559 | return NULL; |
| 1560 | } |
| 1561 | |
| 1562 | static _Noreturn void runtime_cleanup_fail_stop(const char *component); |
| 1563 |
nothing calls this directly
no test coverage detected