wait-cycledeadlock: nav -> gps -> nav
Wait-for loop nav -> gps -> nav: gps is SEND-blocked on nav; nav is REPLY-blocked on gps. Nobody in the loop can ever reply. Also stuck behind it: display.
Evidence: trace events 63860, 63971
Show the 8 trace events behind this
| Event | Time | What happened |
|---|---|---|
| 63840 | 2233.923 ms | display[tid 1] MsgSend to nav (coid 0x40000001, chid 1) message '\x02\x10' |
| 63850 | 2233.943 ms | nav[tid 1] MsgReceive got the message from display[tid 1] |
| 63860 | 2234.026 ms | nav[tid 1] MsgSend to gps (coid 0x40000001, chid 1) message '\x01\x10' |
| 63870 | 2234.051 ms | gps[tid 1] MsgReceive got the message from nav[tid 1] |
| 63971 | 2234.502 ms | gps[tid 1] MsgSend to nav (coid 0x40000002, chid 1) message '\x05\x10' |
| -63972 (note) | - | at trace end gps[tid 1] is still SEND-blocked on nav (no reply to event 63971) |
| -63861 (note) | - | at trace end nav[tid 1] is still REPLY-blocked on gps (no reply to event 63860) |
| -63841 (note) | - | at trace end display[tid 1] is still REPLY-blocked on nav (no reply to event 63840) |
While handling nav's MSG_POSITION request (63860/63870), gps_handle() calls MsgSend() back to nav for a MSG_HINT (63971) before replying. nav's only thread is REPLY-blocked in its own MsgSend() to gps, so it can never MsgReceive() the hint; gps stays SEND-blocked on nav and nav stays REPLY-blocked on gps forever. display, waiting on nav (63840), freezes behind the loop. gps -> nav is also not an allowed edge in blueprint.yaml.
At fault: MsgSend in gps (gps_handle sends MSG_HINT to nav before MsgReply to nav)
Fix: Remove the gps -> nav call. A server must not send to its own client. The contract only allows nav -> gps, so gps must answer MSG_POSITION from its own state. If gps really needs route context, nav should put it in the MSG_POSITION request, or gps should get it later through a non-blocking pulse, never a MsgSend back up the chain.
Proposed patch
--- a/cockpit.c
+++ b/cockpit.c
@@ static int gps_handle(int rcvid, cockpit_msg_t *msg, cockpit_msg_t *reply) {
(void)rcvid;
- if (has_fault("deadlock") && msg->type == MSG_POSITION) {
- /* The regression: gps wants a route hint from nav before answering.
- * nav is blocked waiting on us, so neither side ever replies. */
- if (gps_nav == -1) {
- gps_nav = connect_to("cockpit-nav");
- }
- cockpit_msg_t hint;
- ask(gps_nav, MSG_HINT, msg->seq, "hint?", &hint);
- }
+ /* gps is a leaf server: it must never MsgSend() to nav, its own client.
+ * Any hint nav wants to give belongs in the MSG_POSITION request (msg->text). */
snprintf(reply->text, sizeof(reply->text), "pos %d.%03d", 50, 450 + msg->seq % 100);
return 0;
}Cites events 63840, 63850, 63860, 63870, 63971, -63972, -63861, -63841 · Docs: MsgSend MsgReceive MsgReply Synchronous message passing