Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tools tests #38613

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[actionsWithKeyPressed.html]
expected:
if product == "safari": ERROR
26 changes: 17 additions & 9 deletions tools/wptserve/wptserve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,20 @@ def _stream_thread(self, stream_id, queue):
response = None
req_handler = None

def cleanup():
# Try to close the files
# Ignore any exception (e.g. if the file handle was already closed for some reason).
if rfile:
try:
rfile.close()
except OSError:
pass
if wfile:
try:
wfile.close()
except OSError:
pass

while not self.close_connection:
try:
frame = queue.get(True, 1)
Expand All @@ -582,10 +596,7 @@ def _stream_thread(self, stream_id, queue):

self.logger.debug(f'({self.uid} - {stream_id}) {str(frame)}')
if isinstance(frame, RequestReceived):
if rfile:
rfile.close()
if wfile:
wfile.close()
cleanup()

pipe_rfile, pipe_wfile = os.pipe()
(rfile, wfile) = os.fdopen(pipe_rfile, 'rb'), os.fdopen(pipe_wfile, 'wb')
Expand Down Expand Up @@ -626,10 +637,7 @@ def _stream_thread(self, stream_id, queue):
(self.uid, stream_id))
break

if rfile:
rfile.close()
if wfile:
wfile.close()
cleanup()

def frame_handler(self, request, response, handler):
try:
Expand Down Expand Up @@ -854,7 +862,7 @@ def start(self):
self.logger.info(f"Starting {http_type} server on {http_scheme}://{self.host}:{self.port}")
self.started = True
self.server_thread = threading.Thread(target=self.httpd.serve_forever)
self.server_thread.setDaemon(True) # don't hang on exit
self.server_thread.daemon = True # don't hang on exit
self.server_thread.start()

def stop(self):
Expand Down