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
This commit is contained in:
ed 2025-07-01 18:32:27 +00:00
parent 77274e9d59
commit bf11b2a421

View file

@ -313,6 +313,8 @@ class HttpSrv(object):
Daemon(self.broker.say, "sig-hsrv-up1", ("cb_httpsrv_up",)) Daemon(self.broker.say, "sig-hsrv-up1", ("cb_httpsrv_up",))
saddr = ("", 0) # fwd-decl for `except TypeError as ex:`
while not self.stopping: while not self.stopping:
if self.args.log_conn: if self.args.log_conn:
self.log(self.name, "|%sC-ncli" % ("-" * 1,), c="90") 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) self.log(self.name, "accept({}): {}".format(fno, ex), c=6)
time.sleep(0.02) time.sleep(0.02)
continue 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: if self.args.log_conn:
t = "|{}C-acc2 \033[0;36m{} \033[3{}m{}".format( t = "|{}C-acc2 \033[0;36m{} \033[3{}m{}".format(