@@ -78,6 +78,8 @@ def __init__(self, callback, conf_root, listen_ipv4=None, listen_ipv6=None, defa
78
78
79
79
self .client_socket_addrs = {}
80
80
81
+ self .select_timeout = None # Set on shutdown to prevent infinite wait
82
+
81
83
self .pemfile = normalize_path (pemfile if pemfile is not None else options .server .pemfile , conf_root )
82
84
self .cacert = normalize_path (cacert if cacert is not None else options .server .cacert , conf_root )
83
85
@@ -171,17 +173,16 @@ def run(self):
171
173
172
174
while True :
173
175
try :
174
- r , w , e = select .select (self .all_socks , [], self .all_socks )
176
+ if self .select_timeout :
177
+ r , w , _ = select .select (self .all_socks , [], [], self .select_timeout )
178
+ else :
179
+ r , w , _ = select .select (self .all_socks , [], [])
175
180
except Exception as exc :
176
181
if isinstance (exc , select .error ) and exc .args [0 ] == 4 :
177
182
continue # Got signal, probably HUP
178
183
else :
179
184
raise
180
185
181
- for sock in e :
182
- # Disconnect error streams
183
- self .disconnect_client_stream (sock )
184
-
185
186
for sock in r :
186
187
if sock in self .dgram_socks :
187
188
# Receive datagram
@@ -298,15 +299,16 @@ def close(self):
298
299
for sock in self .client_stream_socks :
299
300
sock .shutdown (socket .SHUT_RDWR )
300
301
301
- time .sleep (self .SHUTDOWN_TIMEOUT )
302
+ if self .client_stream_socks :
303
+ time .sleep (self .SHUTDOWN_TIMEOUT )
302
304
303
305
for sock in self .all_socks :
304
306
sock .close ()
305
307
306
-
307
308
def shutdown (self ):
308
309
'''Notifies the server of a shutdown condition.'''
309
310
310
311
self .closed = True
312
+ self .select_timeout = self .SHUTDOWN_TIMEOUT
311
313
312
314
0 commit comments