From ba8be1d6d5406bfb2dea1b3e9c2c1f6356b14dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Dzia=C5=82ak?= Date: Tue, 1 Oct 2024 23:57:02 +0200 Subject: [PATCH] Invoke TConn().init() in gunicorn worker thread. MainThread in gunicorn gthread worker calls TConn().init() function, but when ssl is used that function may raise an ENOTCONN exception. There is very low probability for that, but still it is needed to catch potential socket errors during that call, otherwise whole gunicorn worker with all threads will be crashed. --- gunicorn/workers/gthread.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gunicorn/workers/gthread.py b/gunicorn/workers/gthread.py index 7a23228cd..012cff846 100644 --- a/gunicorn/workers/gthread.py +++ b/gunicorn/workers/gthread.py @@ -46,6 +46,8 @@ def __init__(self, cfg, sock, client, server): self.sock.setblocking(False) def init(self): + if self.initialized: + return self.initialized = True self.sock.setblocking(True) @@ -111,7 +113,6 @@ def _wrap_future(self, fs, conn): fs.add_done_callback(self.finish_request) def enqueue_req(self, conn): - conn.init() # submit the connection to a worker fs = self.tpool.submit(self.handle, conn) self._wrap_future(fs, conn) @@ -273,6 +274,7 @@ def handle(self, conn): keepalive = False req = None try: + conn.init() req = next(conn.parser) if not req: return (False, conn)