Skip to content

Commit 8c2fe02

Browse files
committed
Handle timeout exception in roundup-server better.
A timeout in roundup-server used to generate another exception: OSError: cannot read from timed out object when it tried to reuse the socket that timed out. Now return status 408, a brief message and trigger closing of the socket. Manual testing, no CI. To test used curl -X POST with no --data defined.
1 parent 6e35fc1 commit 8c2fe02

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ Fixed:
7171
uninitialized list element on a (Mini)FieldStorage when unexpected
7272
input is posted via wsgi. (Reported and debugged by Christof
7373
Meerwald; fix John Rouillard)
74+
- close http socket and send a 408 status when a timeout exception
75+
is handed in roundup-server. This prevents another exception
76+
caused by using a timed out socket. (John Rouillard)
7477

7578
Features:
7679

roundup/scripts/roundup_server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,15 @@ def run_cgi(self):
282282
exc, val, tb = sys.exc_info()
283283
if hasattr(socket, 'timeout') and isinstance(val, socket.timeout):
284284
self.log_error('timeout')
285+
self.send_response(408)
286+
self.send_header('Content-Type', 'text/html')
287+
288+
output = s2b('''<body><p>Connection timed out</p></body>''')
289+
# Close connection
290+
self.send_header('Content-Length', len(output))
291+
self.end_headers()
292+
self.wfile.write(output)
293+
self.close_connection = True
285294
else:
286295
self.send_response(400)
287296
self.send_header('Content-Type', 'text/html')

0 commit comments

Comments
 (0)