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 <haibin.wen3@gmail.com>
This commit is contained in:
nitrobass24
2026-11-28 23:29:56 -05:00
committed by GitHub
parent 4886d4ff5e
commit 1ee68c19e0
+6
View File
@@ -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__()