Commit 6309ef8
committed
Move SSL handshake from main thread to worker thread
Port fix from gunicorn PR #3440. Previously, conn.init() (which does
the SSL handshake via ssl_wrap_socket) ran on the main event loop thread
in enqueue_req() with no error handling. A failed TLS handshake from any
client (port scanners, browsers rejecting self-signed certs, connection
resets) would crash the entire worker process and all its in-flight
connections.
Now conn.init() runs inside handle() in the thread pool, where
ssl.SSLError, OSError, and Exception are already caught. A failed
handshake only affects that one connection.
Also:
- Add double-init guard to TConn.init() for keepalive safety
- Set initialized=True only after success, so partial init failures
propagate the real error instead of a confusing AssertionError
- Set setblocking(True) explicitly in handle() for keepalive
connections where finish_request switched to non-blocking1 parent 04608a4 commit 6309ef8
1 file changed
+11
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
| 67 | + | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
133 | | - | |
134 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
| |||
303 | 306 | | |
304 | 307 | | |
305 | 308 | | |
306 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
307 | 313 | | |
308 | 314 | | |
309 | 315 | | |
| |||
0 commit comments