Skip to content

Commit

Permalink
Invoke TConn().init() in gunicorn worker thread.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ddzialak committed Oct 1, 2024
1 parent 903792f commit ba8be1d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gunicorn/workers/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ba8be1d

Please sign in to comment.