Every pass of the mojo kernel loop ran these synchronously; each could
stall the loop (and get la_mojo killed by the watchdog):
- Report cleanup (validateReports -> deleteReportDate): deleteRDFDir
ran "rm -f -R <whole day>" (seconds to minutes on an SD card), daily or
every second while the disk is above preserve_empty. The day is now
deleted in a background thread (one at a time; calls during it return
false). ~sqliteDBC waits for a running deletion (max 60 s).
- MediaMTX (validateService -> restart): "systemctl restart" waited for
the service to stop and start, every second if the config kept failing
validation. Now "systemctl --no-block restart" (only queues the job),
at most once per KH_MTX_RESTART_MIN_S (30 s).
- IP UART serial provider (hardwareManager::validate -> create_SOL): a
blocking connect() to an address that doesn't answer took ~2 min (SYN
retries). Now non-blocking with SERIAL_SOL_CONNECT_TIMEOUT_MS (5 s),
the socket mode restored afterwards, and the socket closed on failure
(it leaked).
- Ethernet2UART gateway nodes: hardwareManager::validate (kernel loop)
validated and reconnected them again, although the node factory thread
does it (deviceNode::validate). Connects of up to 5 s blocked the kernel
loop, plus the wait for the node's connection lock.
hardwareResource::selfValidating() (default false) is true for
deviceETH2UART, and the hardware manager skips such resources.
Tested: the connect timeout on its own (extracted unchanged). A peer
that drops the SYN failed after 5002 ms ("Connection timed out") instead
of ~2 min; refused and accepted connects are immediate; the socket is
blocking again in every case.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234):
deviceETH2UART
- In TCP mode, link health is the TCP connection itself (socket, I/O
thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on
mobile networks often don't answer ping, and the working connection was
closed every second ("No Ping to device!").
- Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an
echo reply from the gateway with our id and sequence counts. A signal
(EINTR) no longer ends the wait. The old single recvfrom() with
SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART.
- TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in
select() continues waiting.
- create_SOL() closes the previous socket and I/O thread first. It
overwrote the socket (the connection leaked) and init() failed while
the old thread ran, so each reconnect left an open TCP connection at the
gateway and the node stayed invalid although "Connected". If init()
fails, the new socket is closed.
- create()/validate()/reconnect() are serialised: they run on the node
factory thread and on the hardware manager thread.
- Registered with the hardware manager once. Re-creation from the
hardware manager locked its non-recursive list mutex again (deadlock).
- Reconnect back-off 2 s -> 30 s.
- recv() == 0 on TCP means the gateway closed the connection (a stale
errno was checked before).
- Destructor resigns from the hardware manager before closing.
deviceNodeFactory
- deleteNode() deletes the gateway object. It was only removed from the
list and kept running next to the new node created for the same id.
- Nodes are deleted after the validation loop (erasing inside it skipped
the next node).
deviceNode::validate
- Compares the configuration only. "online" changes whenever another
object of the same node id is created or deleted.
hardwareManager::assignResource
- Ignores a resource that is already assigned.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16