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.
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
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.
@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
@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
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)
@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
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
@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 ?
mac, and I don't install it on run time each time. It is just there
+1
I've started running into this as well with a Docker / CI build.
@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.
@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
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!
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
Is there a solution for this? We recently started encountering this one after using driver 2.27 and Chrome 55
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
@krasnoukhov can you please share/explain how your patch is being used? Where should it be added? Thanks.
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
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
@piotrmasior How did you solve the port failures?
It appeared that latest firefox works with gekodriver which in its turn
works badly with latest selenium onCI hesdless, same with chromedriver but
a bit better, still reverting to older version of selenium ehich works
directly with browser solved problem for me, its version <3 selenium i
think, hope helps to someone
11.04.2017 5:08 пользователь "Paul Schroeder" notifications@github.com
написал:
@piotrmasior https://github.com/piotrmasior How did you solve the port
failures?—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/SeleniumHQ/docker-selenium/issues/198#issuecomment-293079463,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AUU6cU3YeMVb6GvTCrHvF4j_6Ee4MgUEks5rupo4gaJpZM4IBD0S
.
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 :(
@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.
@krasnoukhov do you've any samples in your repo ? would be much helpful
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"])])
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
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.
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.
Try using different version of chromedriver or geckodriver, usually its.more downgraded version
Most helpful comment
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
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