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 none
Show the 2 trace events behind this
| Event | Time | What happened |
|---|---|---|
| -10000001 (note) | - | pidin: nav pid 749593 tid 1 REPLY-blocked on gps pid 749591 (state when the trace stopped) |
| -10000000 (note) | - | pidin: gps pid 749591 tid 1 SEND-blocked on nav pid 749593 (state when the trace stopped) |
nav handles display's MSG_ROUTE by calling MsgSend() to gps (MSG_POSITION) and is REPLY-blocked on gps. In the deadlock build, gps_handle() calls MsgSend() back to nav (MSG_HINT) before replying. nav's only thread is stuck in its own MsgSend() and never gets back to MsgReceive(), so gps stays SEND-blocked, nav stays REPLY-blocked, and display waits behind nav forever. The gps -> nav send also breaks the contract, which allows only nav -> gps.
At fault: MsgSend from gps to nav (MSG_HINT) inside gps_handle, made before MsgReply to nav
Fix: Remove the gps -> nav send. gps must answer MSG_POSITION using only its own state and must never send up the hierarchy to its client (blueprint allows nav -> gps only). If gps really needs hints from nav, nav should push them down in the request, for example in the text or subtype field of MSG_POSITION, or with a separate nav -> gps message. Calling back to nav is never correct.
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 travels down in the MSG_POSITION request. */
snprintf(reply->text, sizeof(reply->text), "pos %d.%03d", 50, 450 + msg->seq % 100);
return 0;
}Cites events -10000001, -10000000 · Docs: MsgSend MsgReceive MsgReply Synchronous message passing