Skip to content

Commit

Permalink
Browser#alive?: Removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Zapotek committed Dec 18, 2021
1 parent 0c148ef commit 4cbb43d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 139 deletions.
172 changes: 36 additions & 136 deletions lib/arachni/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,37 +383,6 @@ def wait_till_ready
wait_for_pending_requests
end

def shutdown
print_debug 'Shutting down...'

if @selenium
print_debug_level_2 'Quiting Selenium...'
# So freaking hacky but @selenium.quit freezes for some reason.
@selenium.instance_eval do
bridge.quit

@service.instance_eval do
Processes::Manager.kill @process.pid
end
end

print_debug_level_2 '...done.'
end

if @proxy
print_debug_level_2 'Shutting down proxy...'
@proxy.shutdown rescue Reactor::Error::NotRunning
print_debug_level_2 '...done.'
end

@proxy = nil
@watir = nil
@selenium = nil
@browser_url = nil

print_debug '...shutdown complete.'
end

# @return [String]
# Current URL, noralized via #{Arachni::URI.}
def url
Expand Down Expand Up @@ -1142,16 +1111,48 @@ def selenium
'--disable-plugins',
"--user-data-dir=#{dir}",
"--proxy-server=#{proxy_uri.host}:#{proxy_uri.port}",
"--buid=46464646",
"--headless"
]
),
http_client: Selenium::WebDriver::Remote::Http::Typhoeus.new
)
end

def alive?
# @lifeline_pid && Processes::Manager.alive?( @lifeline_pid )
true
def shutdown
print_debug 'Shutting down...'

if @selenium
@selenium.close

print_debug_level_2 'Quiting Selenium...'
# So freaking hacky but @selenium.quit freezes if we don't detach first.
@selenium.instance_eval do
bridge.quit

@service.instance_eval do
Process.detach @process.pid
@process.stop
end
end

@selenium.quit rescue Errno::ECONNREFUSED
# @selenium.quit rescue Selenium::WebDriver::Error::WebDriverError
print_debug_level_2 '...done.'

end

if @proxy
print_debug_level_2 'Shutting down proxy...'
@proxy.shutdown rescue Reactor::Error::NotRunning
print_debug_level_2 '...done.'
end

@proxy = nil
@watir = nil
@selenium = nil

print_debug '...shutdown complete.'
end

def inspect
Expand Down Expand Up @@ -1244,107 +1245,6 @@ def value_for_name( name )
Options.input.value_for_name( name )
end

# def spawn_browser
# if !spawn_phantomjs
# fail Error::Spawn, 'Could not start the browser process.'
# end
#
# @browser_url
# end
#
# def spawn_phantomjs
# return @browser_url if @browser_url
#
# print_debug 'Spawning PhantomJS...'
#
# ChildProcess.posix_spawn = true
#
# port = nil
# output = ''
#
# 10.times do |i|
# # Clear output of previous attempt.
# output = ''
# done = false
# port = Utilities.available_port
#
# start_proxy
#
# print_debug_level_2 "Attempt ##{i}, chose port number #{port}"
#
# begin
# with_timeout BROWSER_SPAWN_TIMEOUT do
# print_debug_level_2 "Spawning process: #{self.class.executable}"
#
# r, w = IO.pipe
# ri, @kill_process = IO.pipe
#
# @lifeline_pid = Processes::Manager.spawn(
# :browser,
# executable: self.class.executable,
# without_arachni: true,
# fork: false,
# new_pgroup: true,
# stdin: ri,
# stdout: w,
# stderr: w,
# port: port,
# proxy_url: @proxy.url
# )
#
# w.close
# ri.close
#
# print_debug_level_2 'Process spawned, waiting for WebDriver server...'
#
# # Wait for PhantomJS to initialize.
# while !output.include?( 'running on port' )
# begin
# output << r.readpartial( 8192 )
# # EOF or something, take a breather before retrying.
# rescue
# sleep 0.05
# end
# end
#
# @browser_pid = output.scan( /^PID: (\d+)/ ).flatten.first.to_i
#
# print_debug_level_2 '...WebDriver server is up.'
# done = true
# end
# rescue Timeout::Error
# print_debug 'Spawn timed-out.'
# end
#
# if !output.empty?
# print_debug_level_2 output
# end
#
# if done
# print_debug 'PhantomJS is ready.'
# break
# end
#
# print_debug_level_2 'Killing process.'
#
# # Kill everything.
# shutdown
# end
#
# # Something went really bad, the browser couldn't be spawned even
# # after our valiant efforts.
# #
# # Bail out for now and count on the BrowserCluster to retry to boot
# # another process ass needed.
# if !@lifeline_pid
# log_error 'Could not spawn browser process.'
# log_error output
# return
# end
#
# @browser_url = "http://127.0.0.1:#{port}"
# end

def start_proxy
print_debug 'Booting up...'

Expand All @@ -1366,7 +1266,7 @@ def start_proxy
def start_webdriver
print_debug_level_2 'Starting WebDriver...'
@watir = ::Watir::Browser.new( selenium )
print_debug_level_2 "... started WebDriver at: #{@browser_url}"
print_debug_level_2 "... started WebDriver."

print_debug '...boot-up completed.'
end
Expand Down
6 changes: 3 additions & 3 deletions lib/arachni/browser_cluster/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def shutdown( wait = true )

# Keep checking to see if any of the 'done' criteria are true.
kill_check = Thread.new do
while alive? && wait && @job
while wait && @job
print_debug_level_2 "Waiting for job to complete: #{job}"
sleep 0.1
end
Expand Down Expand Up @@ -236,12 +236,12 @@ def start
end

def browser_respawn_if_necessary
return false if !time_to_die? && alive?
return false if !time_to_die?
browser_respawn
end

def browser_respawn
print_debug "Re-spawning browser (TTD?: #{time_to_die?} - alive?: #{alive?}) ..."
print_debug "Re-spawning browser (TTD?: #{time_to_die?}) ..."
@time_to_live = @max_time_to_live

browser_shutdown
Expand Down

0 comments on commit 4cbb43d

Please sign in to comment.