Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net::ReadTimeout during browser launch (Watir and selenium/standalone-chrome) #198

Closed
jizel opened this issue Apr 6, 2016 · 29 comments
Closed

Comments

@jizel
Copy link

jizel commented Apr 6, 2016

Hi,
I am using Watir/docker-selenium/Jenkins combo for automation and I've been experiencing an issue with selenium/standalone-chrome image for quite some time.

When launching new browser in Ruby (yield self.browser(browser_type='chrome')) I get a Net::ReadTimeout error very often.
What I do is to rescue it and launch the browser again so my test suite is not affected. Altough that works as workaround it doesn't solve the problem and - happening really often (10-20 times out of 200 scenarios) - it slows the whole suite down .

This is not an issue for selenium/standalone-firefox, neither for any chrome browser outside docker. It also has nothing to do with client.timeout which is set to 3 minutes in my case - it fails immediately.

Though this issue (http://stackoverflow.com/questions/34003347/how-to-get-concurrent-tests-to-run-with-chrome-in-jenkins) may induce otherwise it does not happen only for multiple users, it happens for single chrome user as well.
It is also independent of Jenkins environment, it happens when running directly on the CentOS VM too.

Thanks.

@shames0
Copy link

shames0 commented Apr 22, 2016

I too am noticing this problem, though I'm not using Jenkins, I'm just using the images provided by this repo. Here's the error and trace I'm receiving:

/usr/share/ruby/net/protocol.rb:158:in `rescue in rbuf_fill': Net::ReadTimeout (Net::ReadTimeout)                                                                                                                   
    from /usr/share/ruby/net/protocol.rb:152:in `rbuf_fill'                                                                                                                                                         
    from /usr/share/ruby/net/protocol.rb:134:in `readuntil'                                                                                                                                                         
    from /usr/share/ruby/net/protocol.rb:144:in `readline'                                                                                                                                                          
    from /usr/share/ruby/net/http/response.rb:39:in `read_status_line'                                                                                                                                              
    from /usr/share/ruby/net/http/response.rb:28:in `read_new'                                                                                                                                                      
    from /usr/share/ruby/net/http.rb:1414:in `block in transport_request'                                                                                                                                           
    from /usr/share/ruby/net/http.rb:1411:in `catch'                                                                                                                                                                
    from /usr/share/ruby/net/http.rb:1411:in `transport_request'                                                                                                                                                    
    from /usr/share/ruby/net/http.rb:1384:in `request'                                                                                                                                                              
    from /usr/share/ruby/net/http.rb:1377:in `block in request'                                                                                                                                                     
    from /usr/share/ruby/net/http.rb:853:in `start'                                                                                                                                                                 
    from /usr/share/ruby/net/http.rb:1375:in `request'                                                                                                                                                              
    from /usr/share/gems/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for'                                                                                          
    from /usr/share/gems/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'                                                                                               
    from /usr/share/gems/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'                                                                                                   
    from /usr/share/gems/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/bridge.rb:640:in `raw_execute'                                                                                                
    from /usr/share/gems/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/bridge.rb:101:in `create_session'                                                                                             
    from /usr/share/gems/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/remote/bridge.rb:68:in `initialize'                                                                                                  
    from /usr/share/gems/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/common/driver.rb:33:in `new'                                                                                                         
    from /usr/share/gems/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/common/driver.rb:33:in `for'                                                                                                         
    from /usr/share/gems/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver.rb:67:in `for'                                                                                                                       
    from /var/ruby/lib/Options.rb:7:in `block in driver'                                                                                                                                                            
    from /var/ruby/lib/Options.rb:13:in `call'                                                                                                                                                                      
    from /var/ruby/lib/Options.rb:13:in `driver' 

For additional note, here's the relevant contents of the Options file mentioned in that trace:

  5     def driver()
  6         return @driver ||= (lambda {
  7             driver = Selenium::WebDriver.for(
  8                 :remote,
  9                 :desired_capabilities => :chrome,
 10             )
 11             driver.manage.timeouts.implicit_wait = 10 # seconds
 12             return driver
 13         }).call;
 14     end

@jizel
Copy link
Author

jizel commented Apr 27, 2016

Yes it has nothing to do with Jenkins, sorry for the redundancy in my post. The trace looks absolutely same for me.

I use
@browser = Watir::Browser.new :remote, :url=>"http://127.0.0.1:4444/wd/hub", http_client: client, desired_capabilities: caps
as my browser object.

@timsheng
Copy link

@jizel i met this issue as well, it happens from time to time, and no any regular condition, looks like the browser driver dead, or network issue, setting page level or element level waiting time didn't work as well. could you share your current code to fix this issue temporarily

@jizel
Copy link
Author

jizel commented Jul 25, 2016

@timsheng, What I do is simply to rescue the exception and call my browse method recursively (you might get the exception several times in a row). I have a global counter of recursive calls to prevent forever recursion.

This is my browse method (the important bit):

 begin
      yield self.browser(browser_type)
  rescue Net::ReadTimeout
      STDOUT.puts 'Net::ReadTimeout during browser launch. Trying to launch the browser again'.red
      self.close
      sleep 5
      @read_timeouts += 1
      unless @read_timeouts > 2
        browse(browser_type=browser_type, selected_language = 'en-US', continue = true, &block)
      end
end

@gustavoriveray
Copy link

gustavoriveray commented Sep 9, 2016

Im using cucumber with ruby and selenium and Im having the same issue when running in Jenkins. For ruby I use rvm with ruby 2.3.0.

I started seeing this error in Chrome 52 with Chromedriver 2.15, which was very old from Chromedriver-Helper gem. These are my gems

Using awesome_print 1.7.0
Using json 1.8.3
Using mini_portile2 2.1.0
Using pkg-config 1.1.7
Using ffi 1.9.14
Using rubyzip 1.2.0
Using websocket 1.2.3
Using tomlrb 1.2.3
Using io-like 0.3.0
Using ast 2.3.0
Using thread_safe 0.3.5
Using ice_nine 0.11.2
Using builder 3.2.2
Using coderay 1.1.1
Using gherkin 3.2.0
Using cucumber-wire 0.0.1
Using diff-lcs 1.2.5
Using multi_json 1.12.1
Using multi_test 0.1.2
Using tilt 2.0.5
Using equalizer 0.0.11
Using multi_xml 0.5.5
Using mimemagic 0.3.2
Using multipart-post 2.0.0
Using method_source 0.8.2
Using rspec-support 3.5.0
Using powerpack 0.1.1
Using rainbow 2.1.0
Using ruby-progressbar 1.8.1
Using slop 3.6.0
Using bundler 1.13.0
Using nokogiri 1.6.8
Using childprocess 0.5.9
Using archive-zip 0.7.0
Using parser 2.3.1.2
Using descendants_tracker 0.0.4
Using cucumber-core 1.4.0
Using haml 4.0.7
Using httparty 0.14.0
Using rspec-expectations 3.5.0
Using rspec-core 3.5.3
Using rspec-mocks 3.5.0
Using pry 0.10.4
Using selenium-webdriver 2.53.4
Using chromedriver-helper 1.0.0
Using astrolabe 1.3.1
Using axiom-types 0.1.1
Using coercible 1.0.0
Using cucumber 2.3.2
Using httmultiparty 0.3.16
Using rspec 3.5.0
Using appium_lib 8.0.2
Using virtus 1.0.5
Using cucumber_statistics 2.1.1

It kept failing after upgrading Chromedriver 2.23 and then after upgrading Chrome to 53. However something weird happens. It starts failing, and keeps doing it for a day, then fixes itself for, about half a day. (The job runs every 15 min). Then fails again for a day. Also if I restart the machine, it starts passing again for about a day.

The error I get is

  Failed to start driver: Net::ReadTimeout
  Net::ReadTimeout (Net::ReadTimeout)

@kevin-andres
Copy link

@gustavoriveray I am experiencing the same issue as you, with nearly the same set up of Cucumber, Ruby (rvm 2.3.0), Selenium WebDriver (chrome) running on Jenkins..Although I have run the same exact test with Firefox as the browser and it works fine..Cannot get it to work with chromedriver 2.24.417424 and Chrome 53

@gustavoriveray
Copy link

I reinstalled Chrome @kevin-andres and it seems to have solve the problem, for some reason, it has been running passing for about a week now

@kevin-andres
Copy link

@gustavoriveray Glad to hear that. Are you running your Jenkins on Linux? If so, did you use do the installation with: apt-get install google-chrome-stable ?

@gustavoriveray
Copy link

mac, and I don't install it on run time each time. It is just there

@earnold
Copy link

earnold commented Sep 30, 2016

+1
I've started running into this as well with a Docker / CI build.

@kevin-andres
Copy link

@earnold It turns out that Chrome crashes if you try to run it on Docker. (I'm guessing you're having the same issue as me, trying to run Chrome/chromedriver on Jenkins CI w/ docker). It's caused by the shared memory on the container being too small by default for Chrome to run. There are a couple of known solutions to working around this, but basically /dev/shm is too small. I followed those steps, and was able to get my Selenium WebDriver tests to finally pass using Chrome.

@earnold
Copy link

earnold commented Oct 11, 2016

@kevin-andres Thanks for the guidance! It took some doing, but I also need to set --cap-add=SYS_ADMIN in order to get this running. Not sure what the ramifications of that are, but at least my specs are running

@ddavison
Copy link
Member

ddavison commented Oct 11, 2016

yes, this has to do with how small docker containers are. they are designed to be extremely minimal. running browsers (especially chrome) is a hefty task.

unfortunately - as far as i know, there is nothing we can do on these containers regarding this.

please see this comment

the best thing to do is to share the hosts memory. considering this, i will be closing this issue. if there are solutions that are offered in the README.md files specific to the nodes, pull requests are gladly accepted!

@Th33x1l3
Copy link

i tried the /dev/shm solution on the container (both by trying to mount /dev/shm from host, or by trying the switch) and it still happens

@TruptiPotdar-Edmodo
Copy link

Is there a solution for this? We recently started encountering this one after using driver 2.27 and Chrome 55

@krasnoukhov
Copy link

We came up with a following monkey-patch until we can upgrade to Selenium 3.x. Problem is gone for now:

# NOTE: this is to fix random Chrome shutdown failure on CI
# Should be fixed in selenium >= 3.0.0
class Selenium::WebDriver::Chrome::Service
  alias_method :original_stop, :stop

  def stop
    original_stop
  rescue Net::ReadTimeout
  end
end

@prashanw
Copy link

@krasnoukhov can you please share/explain how your patch is being used? Where should it be added? Thanks.

@qwebek
Copy link

qwebek commented Feb 21, 2017

Having this issue with cucumber firefox selenium xvfb, for me it happens on any page redirect, first page loads fine but when you move to other page i have subject error all the time

@piotrmasior
Copy link

it is not docker issue
easiest way to reproduce that is spawn chromedriver and initialize session to it
kill chromedriver, and try any action again

in my case it was problem with --port arg on chromedriver as it fails SILENTLY with bind problem if port already in use

@pschroeder89
Copy link

@piotrmasior How did you solve the port failures?

@qwebek
Copy link

qwebek commented Apr 10, 2017 via email

@aakashgupta96
Copy link

I have tried expanding the size of /dev/shm but still it is not working for me :( I'm trying to run headless test with selenium ruby bindings and chrome drivers on Digital Ocean Ubuntu 14.04. Chrome driver version is 2.29 and and google-chrome version is 57.0

But whener I try to start a new session with these commands

headless=Headless.new
headless.start
driver = Selenium::WebDriver.for :chrome

Net::ReadTimeout: Net::ReadTimeout
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/protocol.rb:158:in `rbuf_fill'

I tried the same on a docker container on my local machine and still I am facing the same issue.

I can run it successfully on my local machine(without using docker container) and AWS server as well. Please help me to fix this :(

@elgalu
Copy link
Member

elgalu commented Apr 18, 2017

@aakashgupta96 : https://github.com/leonid-shevtsov/headless is incompatible with docker-selenium, please open that issue in leonid-shevtsov/headless repo or drop it altogether, i.e. drop Headless class and gem and connect to the selenium grid of docker-selenium.

@prashanth-sams
Copy link

@krasnoukhov do you've any samples in your repo ? would be much helpful

@dmitrym0
Copy link

For whatever it's worth, if you run tests as root (I know, I know) Chromium will block with an error asking for --no-sandbox parameter to be passed. Because Chromium is blocking, Chromedriver times out and you get the error above.

I solved it with:

    Watir::Browser.new(:chrome,
                      :prefs => {:password_manager_enable => false, :credentials_enable_service => false},
                      :switches => ["disable-infobars", "no-sandbox"])])

@damontgomery
Copy link

I'm not using docker-selenium, but I got a similar issue and dmitrym0's response fixed it. I added --no-sandbox. Without this, sometimes it works and sometimes it doesn't. :(

I'm also running docker with the --cap-add=SYS_ADMIN option.

I'm using a custom Dockerfile based on the official Ruby Dockerfile and then installing Chromedriver and Chrome.

Something like the following which runs the command in docker and then gets rid of the container when it's done.
docker run --cap-add=SYS_ADMIN --rm -v "${DIR}/:/usr/src/app/" -it cucumber cucumber "$@"

My cucumber (ruby) configuration looks like,

Capybara.register_driver :custom_chrome_headless do |app|
  browser_options = ::Selenium::WebDriver::Chrome::Options.new()
  browser_options.args << '--headless'
  browser_options.args << '--no-sandbox'
  browser_options.args << '--disable-gpu'
  browser_options.args << '--window-size=1920,1080'
  Capybara::Selenium::Driver.new(app,
    browser: :chrome,
    options: browser_options
  )
end

@PhilipJordan
Copy link

PhilipJordan commented Jan 8, 2018

This issue still exists. You can recreate it by using this script:


require 'watir'
 
 def get_arguments
   browser_arguments = { }
 
   capabilities = Selenium::WebDriver::Remote::Capabilities.chrome()
 
   capabilities[:name] = 'Watir'
   browser_arguments[:opt] = capabilities
 
   browser_arguments
 end
 
 #recursive call to get browser instance due to bug 
 def get_browser(iterations)
   raise "Unable to instantiate browser after #{iterations} iterations" if iterations < 0
   begin
     browser_arguments = get_arguments
     browser = Watir::Browser.new :chrome, :prefs => browser_arguments, :switches => %w(disable-infobars no-sandbox)
     browser.goto 'www.google.com'
   rescue
     return get_browser(iterations - 1)
   end
   browser
 end
  
 $browsers = {}
 
 15.times { |index|
   browser_arguments = get_arguments
 
   browser = Watir::Browser.new :chrome, :prefs => browser_arguments, :switches => %w(disable-infobars no-sandbox)
 
   #one viable solution 
   #browser = get_browser(3)
 
   $browsers[index] = browser unless browser.nil?
 }
 
 sleep 3

Note that one viable solution (that others mention above) has been provided and I have also added suggested switches (i.e. no-sandbox) as some suggested. Even with 15 browsers this script will sometimes make it all the way through without failure so you may need to run it more than once to create the error.

@corbett3289
Copy link

Still having this issue and not sure how other users are solving this. I've tried the no-sandbox method and that doesn't appear to work.

@qwebek
Copy link

qwebek commented May 21, 2019

Try using different version of chromedriver or geckodriver, usually its.more downgraded version

@lock lock bot locked and limited conversation to collaborators Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests