Skip to content

Commit 1f25a8f

Browse files
committed
Reliably kill Processes on Windows
1 parent 8787787 commit 1f25a8f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/ferrum/browser/process.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def self.process_killer(pid)
3434
proc do
3535
begin
3636
if Ferrum.windows?
37-
::Process.kill("KILL", pid)
37+
# Process.kill is unreliable on Windows
38+
::Process.kill("KILL", pid) unless system("taskkill /f /t /pid #{pid} >NUL 2>NUL")
3839
else
3940
::Process.kill("USR1", pid)
4041
start = Ferrum.monotonic_time
@@ -88,7 +89,7 @@ def start
8889
@xvfb = Xvfb.start(@command.options)
8990
ObjectSpace.define_finalizer(self, self.class.process_killer(@xvfb.pid))
9091
end
91-
92+
9293
@pid = ::Process.spawn(Hash(@xvfb&.to_env), *@command.to_a, process_options)
9394
ObjectSpace.define_finalizer(self, self.class.process_killer(@pid))
9495

0 commit comments

Comments
 (0)