Skip to content

Commit ec28898

Browse files
yezhizhenservo-wpt-sync
authored andcommitted
Solve race condition
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
1 parent ec94cdc commit ec28898

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tools/wptrunner/wptrunner/browsers/servodriver.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mypy: allow-untyped-defs
22

3-
from http.client import HTTPConnection
3+
from http.client import HTTPConnection, ResponseNotReady
44
import os
55
import tempfile
66
import time
@@ -147,11 +147,19 @@ def stop(self, force=False):
147147
conn = HTTPConnection(self.host, self.port)
148148
while self.is_alive():
149149
self.logger.info("Trying to shut down gracefully by extension command")
150-
151-
conn.request("DELETE", "/session/dummy-session-id/servo/shutdown")
152-
res = conn.getresponse()
153-
self.logger.info(f"Got response status for shutdown command: {res.status}")
154-
150+
while True:
151+
try:
152+
conn.request("DELETE", "/session/dummy-session-id/servo/shutdown")
153+
res = conn.getresponse()
154+
self.logger.info(f"Got response status for shutdown command: {res.status}")
155+
except ResponseNotReady:
156+
self.logger.info(f"Shutdown request not sent yet, retrying...")
157+
continue
158+
except Exception as e:
159+
self.logger.info(f"Servo browser already shut down: {e}")
160+
return
161+
# Successfully sent the shutdown command
162+
break
155163
time.sleep(0.1)
156164

157165
def find_wpt_prefs(self, logger):

0 commit comments

Comments
 (0)