Search code examples
firefoxseleniumwebdriverwatir-webdriverheadless

Watir-Webdriver EOFError and Errno::ECONNREFUSED


While running a DelayedJobs queue that uses Watir-Webdriver (with Headless and Firefox) to get some data off the web a few times per hour, I am encountering random EOFError and ECONNREFUSED errors.

It's a reasonably simple script that goes to a site, logs in, enters data in a form and verifies the data returned. However, the errors occur seemingly at random at any point in the script. You can see examples of that below. I think it's also relevant to note that a separate app is running within the same machine, also using Headless, Watir-Webdriver and Firefox.

Because of the randomness, the alternate app, and because Googling led me to this issue with Selenium and ports causing the EOF issue at random, I'm inclined to believe that this is an issue where running Selenium-driven Firefox (via Watir) at the same time is the root cause. So my questions are:

  • What exactly prevents Selenium-driven Firefox from opening two instances that play nicely which each other? Am I right to think port lock-up or some connectivity issue is the likely culprit?
  • How, if possible, can I programmatically avoid these overlapping executions from causing issues?

EOFError examples

For instance, EOFError: end of file reached happens here when trying to .goto:

/home/sam/.rvm/gems/ruby-2.0.0-p353/gems/watir-webdriver-0.7.0/lib/watir-webdriver/browser.rb:77:in `goto'

then on .text:

/home/sam/.rvm/gems/ruby-2.0.0-p353/gems/watir-webdriver-0.7.0/lib/watir-webdriver/elements/element.rb:83:in `text'

ECONNREFUSED examples

Here, Errno::ECONNREFUSED Connection refused - connect(2) happens on .set:

/home/sam/.rvm/gems/ruby-2.0.0-p353/gems/watir-webdriver-0.7.0/lib/watir-webdriver/user_editable.rb:11:in `set'"

then on .click:

/home/sam/.rvm/gems/ruby-2.0.0-p353/gems/watir-webdriver-0.7.0/lib/watir-webdriver/elements/element.rb:119:in `click'

Stack:

  • Mozilla Firefox 31.5.0
  • headless 1.0.2
  • watir-webdriver 0.7.0
  • ruby 2.0.0p353
  • rvm 1.25.25 (stable)
  • CentOS release 6.5 (Final)

Solution

  • I had success giving each app it's own Xvfb display:

    On the server itself:

    $ sudo /usr/bin/Xvfb :98 -screen 0 1280x1024x24 -ac &
    $ sudo /usr/bin/Xvfb :99 -screen 0 1280x1024x24 -ac &
    

    App 1 - before the browser is being created:

    # ~/repo1/whatever.rb
    # ...
    h = headless(:display => '98')
    # ...
    

    App 2 - before the browser is being created:

    # ~/repo2/something.rb
    # ...
    h = headless(:display => '99')
    # ...
    

    @chuck-van-der-linden is probably correct, though, that using VMs or similar are a better solution. If I was starting fresh with this architecture, this would be my approach.