From 1ee68c19e09c8258296791cce3543fc2523e2a43 Mon Sep 17 00:00:00 2001 From: nitrobass24 Date: Sat, 28 Nov 2026 23:29:56 -0500 Subject: [PATCH] statsd: fix StatLogSP hang at exit (#2118) * statsd: close comma_statlog's socket before terminating the shared zmq context StatLogSP and its comma_statlog both connect on zmq.Context.instance(). __del__ ran super().__del__() first, which calls term() on that shared context while comma_statlog's socket is still open, and term() blocks until every socket on the context is closed. A process that had sent a stat hung at exit. Close comma_statlog's socket first, and terminate the context once. Co-authored-by: tonesto7 <1835933+tonesto7@users.noreply.github.com> * cleanup --------- Co-authored-by: tonesto7 <1835933+tonesto7@users.noreply.github.com> Co-authored-by: Jason Wen --- openpilot/sunnypilot/system/statsd.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/openpilot/sunnypilot/system/statsd.py b/openpilot/sunnypilot/system/statsd.py index 09309dd59c..8b5c426267 100755 --- a/openpilot/sunnypilot/system/statsd.py +++ b/openpilot/sunnypilot/system/statsd.py @@ -88,6 +88,12 @@ class StatLogSP(StatLog): self.comma_statlog.connect() def __del__(self): + # shares zmq.Context.instance() with comma_statlog; term() blocks while any socket on it is open + if self.comma_statlog and self.comma_statlog.sock is not None: + self.comma_statlog.sock.close() + self.comma_statlog.sock = None + if self.comma_statlog.zctx is self.zctx: + self.comma_statlog.zctx = None super().__del__() if self.comma_statlog: self.comma_statlog.__del__()