MeshChatX icon indicating copy to clipboard operation
MeshChatX copied to clipboard

[Bug]: Linux backend terminates from SIGPIPE when I2P connection is lost

Open HK1200 opened this issue 1 month ago • 1 comments

MeshChatX version

4.9.2

Release channel

Stable

Platform

Desktop (Electron)

Operating system

Linux

OS details (if Other)

Mint

How did you install MeshChatX?

Linux AppImage

What happened?

On Linux, shutting down or otherwise losing the I2P router while MeshChatX has an active I2P connection causes the ReticulumMeshChatX backend process to terminate. The Electron UI remains running and displays “Disconnected from backend”.

This is reproducible even when I2P is shut down normally from the I2P Router Console; I2P itself does not need to crash.

I traced the backend process with strace and found the failure occurs when Reticulum's I2P watchdog sends its two-byte ~~ keepalive after the I2P socket has broken:

sendto(..., "~~", 2, ...) = -1 EPIPE (Broken pipe)

Immediately afterward, SIGPIPE is delivered and the entire frozen ReticulumMeshChatX process is killed.

I also checked the signal disposition of the healthy backend through /proc/<pid>/status. SIGPIPE is set to its default disposition rather than being ignored or caught. Since the default action for SIGPIPE is process termination, the socket failure kills the backend instead of reaching Reticulum's existing Python exception/reconnection handling.

As a controlled test, I added signal.signal(signal.SIGPIPE, signal.SIG_IGN) to the bundled I2PInterface.py. I verified through /proc/<pid>/status that SIGPIPE was then ignored.

With that one change, repeating the same I2P shutdown no longer terminated the backend. The same backend PID remained alive, Reticulum continued attempting to reconnect to I2P/SAM, and after I restarted I2P and SAM became available, Reticulum automatically restored the I2P connection. MeshChatX did not need to be restarted.

There also appears to be a related diagnostic issue in the Electron backend process manager. Its child exit handler accepts only code, although Node provides (code, signal). A signal-terminated child has a null exit code, and the current handler returns when code == null. As a result, the SIGPIPE responsible for this failure is not retained/reported by MeshChatX.

What did you expect?

Loss or shutdown of the I2P router should take the Reticulum I2P interface offline without terminating the entire MeshChatX backend.

Reticulum should handle the failed socket operation through its existing exception/reconnection logic, keep the MeshChatX backend running, and periodically retry the I2P/SAM connection.

If I2P becomes available again, the I2P interface should reconnect automatically without requiring MeshChatX to be restarted.

This is the behavior observed after experimentally ignoring SIGPIPE: the backend survived the I2P outage and automatically resumed normal I2P traffic after the I2P router and SAM service returned.

Steps to reproduce

  1. On Linux, start I2P and ensure its SAM service is available on TCP port 7656.

  2. Start MeshChatX 4.9.2 with an enabled I2P interface and allow it to establish an I2P peer connection.

  3. Confirm that the ReticulumMeshChatX backend process is running: pgrep -af ReticulumMeshChatX

  4. Optionally attach strace to the backend PID to observe the failure: sudo strace -f -tt -s 256 -e trace=write,writev,sendto,sendmsg,shutdown,close,process,signal -p <BACKEND_PID> -o ~/meshchatx-sigpipe.strace

  5. From the I2P Router Console, perform a normal shutdown of the I2P router while leaving MeshChatX running.

  6. Wait for Reticulum's I2P watchdog/socket handling to encounter the disconnected socket.

  7. Observe that the ReticulumMeshChatX backend process terminates and the still-running MeshChatX Electron frontend displays “Disconnected from backend”.

In my traced reproduction, the final socket operation was a Reticulum I2P keepalive (~~). The write returned EPIPE, SIGPIPE was delivered immediately afterward, and the backend process was killed by SIGPIPE.

Logs or error output

Relevant `strace` output from the `ReticulumMeshChatX` backend:

 id="35kb5c"
sendto(136, "~~", 2, 0, NULL, 0) = 2
...
sendto(136, "~~", 2, 0, NULL, 0) = -1 EPIPE (Broken pipe)
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=35574, si_uid=1000} ---
...
35574 +++ killed by SIGPIPE +++


The `~~` payload corresponds to the I2P watchdog keepalive in the bundled Reticulum `I2PInterface.py`:

 id="z3xg0v"
if (time.time()-self.last_write > I2PInterfacePeer.I2P_PROBE_AFTER*1):
    try:
        if self.socket != None:
            self.socket.sendall(bytes([HDLC.FLAG, HDLC.FLAG]))
    except Exception as e:
        RNS.log("An error ocurred while sending I2P keepalive. The contained exception was: "+str(e), RNS.LOG_ERROR)
        self.shutdown_socket(self.socket)
        should_run = False


`HDLC.FLAG` is `0x7E`, which appears as `~`, matching the two bytes shown by `strace`.

Signal state of the unmodified, healthy backend:

 id="c3sfpy"
SigIgn: 0000000000000000
SigCgt: 00000001000044ea


Decoded relevant signal dispositions:

 id="7wh1fn"
SIGINT  : CAUGHT
SIGABRT : CAUGHT
SIGPIPE : DEFAULT
SIGTERM : CAUGHT


Controlled test patch:

 id="g7pv8a"
import signal
signal.signal(signal.SIGPIPE, signal.SIG_IGN)


After applying the test patch, `/proc/<pid>/status` showed:

 id="9knphx"
SigIgn: 0000000000001000
SigCgt: 00000001000044ea


The `0x1000` bit corresponds to SIGPIPE, confirming it was now ignored.

I then repeated the same I2P shutdown. The backend remained alive with the same PID and did not disconnect from the Electron frontend.

After restarting I2P, Reticulum initially retried SAM while it was unavailable. Once SAM returned, the same backend process automatically resumed I2P operation. Logs showed valid announces and path requests being received through the I2P peer.

The experimental `signal.signal(SIGPIPE, SIG_IGN)` change demonstrates the cause and prevents the failure, but I am not suggesting that `I2PInterface.py` is necessarily the correct location for the permanent fix. Handling SIGPIPE during initialization of the frozen backend may be more appropriate.

Checklist

  • [x] I searched existing issues to avoid duplicates
  • [x] I included my MeshChatX version, channel, operating system, and install method
  • [x] I can reproduce the issue with the steps above

HK1200 avatar Oct 06 '26 10:10 HK1200

Thanks for the report and the logs.

github-actions[bot] avatar Oct 06 '26 10:10 github-actions[bot]