changeset 8269:341841a9edc5

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.
author John Rouillard <rouilj@ieee.org>
date Sun, 12 Jan 2025 12:59:41 -0500
parents 05d8806b25ad
children c70ffbc2a003
files CHANGES.txt roundup/scripts/roundup_server.py
diffstat 2 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Sun Jan 12 12:34:52 2025 -0500
+++ b/CHANGES.txt	Sun Jan 12 12:59:41 2025 -0500
@@ -71,6 +71,9 @@
   uninitialized list element on a (Mini)FieldStorage when unexpected
   input is posted via wsgi. (Reported and debugged by Christof
   Meerwald; fix John Rouillard)
+- close http socket and send a 408 status when a timeout exception
+  is handed in roundup-server. This prevents another exception
+  caused by using a timed out socket. (John Rouillard)
 
 Features:
 
--- a/roundup/scripts/roundup_server.py	Sun Jan 12 12:34:52 2025 -0500
+++ b/roundup/scripts/roundup_server.py	Sun Jan 12 12:59:41 2025 -0500
@@ -282,6 +282,15 @@
             exc, val, tb = sys.exc_info()
             if hasattr(socket, 'timeout') and isinstance(val, socket.timeout):
                 self.log_error('timeout')
+                self.send_response(408)
+                self.send_header('Content-Type', 'text/html')
+
+                output = s2b('''<body><p>Connection timed out</p></body>''')
+                # Close connection
+                self.send_header('Content-Length', len(output))
+                self.end_headers()
+                self.wfile.write(output)
+                self.close_connection = True
             else:
                 self.send_response(400)
                 self.send_header('Content-Type', 'text/html')

Roundup Issue Tracker: http://roundup-tracker.org/