microReticulum icon indicating copy to clipboard operation
microReticulum copied to clipboard

Transport::jobs() deadlocks when the neighbor-probe scan sends a probe

Open sshersh opened this issue 1 month ago • 0 comments

Summary

With neighbor probing enabled (the default), Transport::jobs() can deadlock on itself. When _scan_neighbor_stats() decides a neighbor is suspicious, it sends a probe packet from inside jobs(). That send goes through Transport::outbound(), which spins until _jobs_running is cleared. The flag is only cleared at the end of the same jobs() call, so the loop never returns. On ESP32 this ends in a task watchdog reset.

This is the same reentrancy pattern as #93 / #103 (resource ticks) and #102 (receipt timeouts), but through a different call site, so those fixes don't cover it.

Environment

  • microReticulum 40fa628809d57140180c1c833559ab96fec992c1 (v0.5.0, current master)
  • Used through microReticulum_Firmware, TNC mode with transport enabled
  • Heltec WiFi LoRa 32 V4 (ESP32-S3), Arduino-ESP32 2.0.17

Symptom

We hit this while testing: the board rebooted from the task watchdog every 5 to 6 minutes. Each reboot came right after the 6th packet sent to a direct neighbor. Our traffic was SINGLE packets without proofs, so the neighbor never returned a proof.

Root cause

All links are at 40fa628.

  1. Transport::jobs() sets _jobs_running = true (Transport.cpp#L496) and only clears it near the end (#L1043).

  2. In between, when transport, neighbor probing and the probe destination are all enabled, it calls _scan_neighbor_stats() (#L951-L967).

  3. Once a neighbor has at least NEIGHBOR_SUSPICION_MIN_PKTS (5, Type.h#L529) packets recorded and no recent proof, the scan calls _dispatch_neighbor_probe() (#L5889).

  4. _dispatch_neighbor_probe() calls probe.send() (#L5935), which calls Transport::outbound() (Packet.cpp#L508).

  5. outbound() waits for the job loop to finish (Transport.cpp#L1170-L1174):

    while (_jobs_running) {
        OS::sleep(0.0005);
    }
    

    It is running inside that same jobs() call, so _jobs_running never clears and loop() never returns.

Expected call stack at the hang:

OS::sleep
Transport::outbound
Packet::send
Transport::_dispatch_neighbor_probe
Transport::_scan_neighbor_stats
Transport::jobs
Transport::loop
Reticulum::loop

Possible second call site (unverified)

The failed-link path in jobs() also calls _dispatch_neighbor_probe() directly (#L834-L839). From reading the code it looks like it would hang the same way, but we don't use links and have not reproduced it.

Reproduction conditions

  • Transport enabled, neighbor_probing_enabled() true (the default), probe_destination_enabled() true.
  • The neighbor's identity is known (we have its announce), so _dispatch_neighbor_probe() gets as far as sending.
  • Send 5 or more packets to a direct neighbor that don't come back with a proof (for example SINGLE packets with no proof strategy). The next jobs() pass that runs the scan hangs.

Workaround

RNS::Reticulum::neighbor_probing_enabled(false);

With that set, the same setup ran 15 minutes and 30 packets with no reboots.

Possible fix direction

Just a suggestion: collect the probe targets during jobs() and send the probes after _jobs_running is cleared, the way announce retransmissions in outgoing (and the tick_resources() change in #103) already work. A more general alternative is the in-transport-cycle guard proposed in #93, which would let sends from inside jobs() skip the wait and would cover this call site too.

sshersh avatar Nov 03 '26 15:11 sshersh