From bf11b2a4211510d833139a7b0ebf6e0b18ee1573 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 1 Jul 2025 18:32:27 +0000 Subject: [PATCH] drop corrupted sockets; socket.accept() can fail silently -- this would crash the worker-pool and also produce a confusing useless error-message while doing so reported by someone on a mac with Little Snitch: uv python install cpython-3.13.3-macos-aarch64-none uv python pin cpython-3.13.3-macos-aarch64-none uv sync uv run copyparty ...but was also observed on x86_64 linux with python 2.7 in 2018 (no longer reproduces) fix this to log what's going on and also don't crash --- copyparty/httpsrv.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index 2a3d48ec..75139cc1 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -313,6 +313,8 @@ class HttpSrv(object): Daemon(self.broker.say, "sig-hsrv-up1", ("cb_httpsrv_up",)) + saddr = ("", 0) # fwd-decl for `except TypeError as ex:` + while not self.stopping: if self.args.log_conn: self.log(self.name, "|%sC-ncli" % ("-" * 1,), c="90") @@ -394,6 +396,19 @@ class HttpSrv(object): self.log(self.name, "accept({}): {}".format(fno, ex), c=6) time.sleep(0.02) continue + except TypeError as ex: + # on macOS, accept() may return a None saddr if blocked by LittleSnitch; + # unicode(saddr[0]) ==> TypeError: 'NoneType' object is not subscriptable + if tcp and not saddr: + t = "accept(%s): failed to accept connection from client due to firewall or network issue" + self.log(self.name, t % (fno,), c=3) + try: + sck.close() # type: ignore + except: + pass + time.sleep(0.02) + continue + raise if self.args.log_conn: t = "|{}C-acc2 \033[0;36m{} \033[3{}m{}".format(