Skip to content

Commit 3a051cd

Browse files
PSandroVietND96cgoldbergshbenzer
authored
[py] service: only shutdown if process not terminated (#15183)
* service: only shutdown if process not terminated There are scenarios where a stop() is called on a Service object multiple times. This also happens when explicitly quitting a Webdriver using driver.quit() and afterwards having the garbage collector destroy the service object, calling stop() another time even though the service process has already terminated. The check inside the stop() call only ensured that the process variable is not None, but ignored the fact that the process might already have terminated. Therefor an additional check is introduced to only send the remote shutdown command if the service process has not ended. Fixes #15182 Signed-off-by: Sandro Pischinger <[email protected]> * service: move process termination to finally block If a type error or similar occurs during send_remote_shutdown_command, one should always terminate the service process, even if an exception is thrown. Thus moving self._terminate_process() into a finally block. Signed-off-by: Sandro Pischinger <[email protected]> --------- Signed-off-by: Sandro Pischinger <[email protected]> Co-authored-by: Viet Nguyen Duc <[email protected]> Co-authored-by: Corey Goldberg <[email protected]> Co-authored-by: Simon Benzer <[email protected]>
1 parent cb0d3f3 commit 3a051cd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

py/selenium/webdriver/common/service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ def stop(self) -> None:
152152
elif isinstance(self.log_output, int):
153153
os.close(self.log_output)
154154

155-
if self.process is not None:
155+
if self.process is not None and self.process.poll() is None:
156156
try:
157157
self.send_remote_shutdown_command()
158158
except TypeError:
159159
pass
160-
self._terminate_process()
160+
finally:
161+
self._terminate_process()
161162

162163
def _terminate_process(self) -> None:
163164
"""Terminate the child process.

0 commit comments

Comments
 (0)