From 91ad3af01c45cc43e2705569dc1555789f2fd3f6 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 28 May 2025 08:40:40 +0100 Subject: [PATCH] Use MSG_NOSIGNAL when sending on network sockets. This prevents send(2) from terminating the whole process with SIGPIPE if the socket has gone away. Since PuTTY manages multiple network connections (due to port forwarding and X11 forwarding), and some of the outlying tools like psusan can manage even more (multiple entire sessions running at once), you never want the whole application to die of SIGPIPE in this situation: you just want that one connection (perhaps a forwarding) to be cleanly aborted, and a failure indication sent back over another connection. Even if the main connection really does get EPIPE, you'd still prefer a sensible error message. I tried using psusan this week to forward X11 into a Podman container, by means of sharing a host directory into the container, making psusan bind to a Unix socket in that directory, and telling host PuTTY to connect to that Unix socket and speak bare ssh-connection. The X application locked up mysteriously, and when I tried to ^C it from the main host PuTTY window, psusan in the container died of SIGPIPE at this call site. (The locked-up X app was pterm, which would also be worrying if it weren't for the fact that I can't reproduce it on current main, only on 0.83. I suspect Ben's many recent GTK improvements have fixed something in this area in passing.) --- unix/network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unix/network.c b/unix/network.c index 00848ab8..6271a706 100644 --- a/unix/network.c +++ b/unix/network.c @@ -1121,7 +1121,7 @@ void try_send(NetSocket *s) data = bufdata.ptr; len = bufdata.len; } - nsent = send(s->s, data, len, urgentflag); + nsent = send(s->s, data, len, MSG_NOSIGNAL | urgentflag); noise_ultralight(NOISE_SOURCE_IOLEN, nsent); if (nsent <= 0) { err = (nsent < 0 ? errno : 0);