Skip to content

Commit

Permalink
Add exception handling for JRuby process
Browse files Browse the repository at this point in the history
  • Loading branch information
jemelyah committed Oct 3, 2023
1 parent dcbd0ab commit 6e4aebf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/ferrum/browser/jruby_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
module Ferrum
class Browser
class JrubyProcess < Process
RESCUED_ERRORS = [Errno::ESRCH, Errno::ECHILD, Errno::EBADF].freeze

def start
# Don't do anything as browser is already running as external process.
return if ws_url
Expand Down Expand Up @@ -32,7 +34,11 @@ def start
environment.merge! Hash(@xvfb&.to_env)
end

@process = process_builder.start
@process = begin
process = process_builder.start
sleep @process_timeout
process
end
@pid = @process.pid

parse_ws_url(output_file, @process_timeout)
Expand Down
5 changes: 3 additions & 2 deletions lib/ferrum/browser/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Browser
class Process
KILL_TIMEOUT = 2
WAIT_KILLED = 0.05
RESCUED_ERRORS = [Errno::ESRCH, Errno::ECHILD].freeze

attr_reader :host, :port, :ws_url, :pid, :command,
:default_user_agent, :browser_version, :protocol_version,
Expand Down Expand Up @@ -44,7 +45,7 @@ def self.process_killer(pid)
break
end
end
rescue Errno::ESRCH, Errno::ECHILD
rescue RESCUED_ERRORS
# nop
end
end
Expand Down Expand Up @@ -180,7 +181,7 @@ def close_io(*ios)
ios.each do |io|
io.close unless io.closed?
rescue IOError
raise unless Utils::Platform.jruby?
raise
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ferrum/browser/web_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize(url, max_receive_size, logger)

@driver.parse(data)
end
rescue EOFError, Errno::ECONNRESET, Errno::EPIPE
rescue EOFError, Errno::ECONNRESET, Errno::EPIPE, Errno::EBADF, IOError
@messages.close
end
end
Expand Down

0 comments on commit 6e4aebf

Please sign in to comment.