11

I recently started seeing this error message when trying to run any Cucumber tests. I've done some research and found a few other similar instances of this error, but most of them were browser related issues. I don't see any browser specific error messages in this output:

unable to bind to locking port 7054 within 45 seconds (Selenium::WebDriver::Error::WebDriverError)

I saw another question posted here that was answered (A selenium webdriver exception), however that solution didn't work for me. Running "lsof -i TCP:7054" does not produce any output.

Just in case anyone suggests this, I have already restarted my machine several times and have wiped my gemset and re-ran "bundle".

Here are the relevant gems I'm using:

capybara (0.4.1.2)
cucumber (0.10.7)   
cucumber-rails (0.4.1)
fuubar-cucumber (0.0.9)
selenium-webdriver (0.2.0)

Just to be sure, I've also tried running these tests with Firefox 3.6, 4.0, and 5.0. Same message every time.

Not to be a conspiracy theorist or anything, but everything was working fine before I manually exited running my test suite and ran a pkill on all the active Firefox processes that Cucumber started up. I had about 9 Firefox instances running simultaneously during the test suite. I'm not sure if this would have caused something messed up to happen that would produce the results I'm seeing now from running Cucumber tests.

Does anyone have any suggestions for fixing this issue?

Community
  • 1
  • 1
Joel Andritsch
  • 443
  • 4
  • 12
  • Did you try running the lsof command in the 45 second window while it's waiting to connect? Running with $DEBUG = true (or passing -d to ruby) will give you more debug output. – jarib Jul 28 '11 at 09:39
  • I did run lsof during the first test, within the 45 second window. I still don't get any output. Running with debug mode gives me this error for every gem I have: "Exception `NoMethodError' at rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.15/lib/bundler/lazy_specification.rb:66 - undefined method `to_ary' for json_pure (1.5.1):Bundler::LazySpecification" – Joel Andritsch Jul 28 '11 at 14:29
  • $DEBUG = true will print all rescued exceptions, so a lot of output is expected. Seeing that output would help us diagnose your problem. – jarib Jul 28 '11 at 21:48
  • Sorry, $DEBUG needs to be set as a global variable in your Ruby code, not as an env var. Same thing can be achieved by passing -d to ruby on the command line. – jarib Jul 31 '11 at 17:23

4 Answers4

18

Update: Problem Solved

After setting $DEBUG to true and re-running the tests, this error was most interesting:

<Selenium::WebDriver::Firefox::SocketLock:0x00000102f9c010>: getaddrinfo: nodename nor servname provided, or not known
Exception `SocketError' at /Users/bobrossasaurus/.rvm/gems/ruby-1.9.2-p136/gems/selenium-webdriver-0.2.0/lib/selenium/webdriver/common/platform.rb:131 - getaddrinfo: nodename nor servname provided, or not known

After taking a look at platform.rb:131, I noticed that it was attempting to connect to "localhost" on port 80 but was failing. This raised a red flag, as I was recently having trouble accessing "localhost" via browser and instead had to use 127.0.0.1:3000 to view my rails projects.

The Solution:

I was missing the localhost host file entry in /etc/hosts:

127.0.0.1 localhost

Quite an embarrassing issue, but it was the answer nonetheless.

Joel Andritsch
  • 443
  • 4
  • 12
  • +1: I copied my host file from windows to OS X. Windows does not need the localhost entry (it is handled by DNS), but OS X does. If I had not found your answer probably I would not find out how to solve this issue, so thanks. – rsenna Feb 06 '13 at 17:39
0

Since this is the top scoring entry on this problem in both google and duck duck go, I'll document my workaround here. The problem as I understand it, is that selenium uses port 7054 as a mutex* to solve the problem that firefox upon start forks the real firefox and quits the starter script. Thus the PID of the real fox can only be guessed from selenium and starting multiple copies of firefox in parallel would lead to constant race conditions. Thus the locking port, which then can become a problem if many firefox need to start in parallel.

Our workaround is to increase this timeout.

# Starting many firefoxen in parallel can easily take more than 45 (default) seconds
module Selenium
  module WebDriver
    module Firefox
      class Launcher
        remove_const(:SOCKET_LOCK_TIMEOUT)
      end
    end
  end
end
Selenium::WebDriver::Firefox::Launcher::SOCKET_LOCK_TIMEOUT = 90

in the startup code for selenium.

Fix modeled after this hint: http://www.assertselenium.com/selenium-tips-tricks/

* A mutex is a program object that allows multiple program threads to share the same resource, such as file access, but not simultaneously.

Elijah Lynn
  • 12,272
  • 10
  • 61
  • 91
dwt
  • 128
  • 1
  • 7
0

I was able to reset this constant in an initializer with a bit less work. I needed to set it shorter so my script could just create another browser.

# config/initializers/selenium.rb

module Selenium module WebDriver module Firefox class Launcher Selenium::WebDriver::Firefox::Launcher::SOCKET_LOCK_TIMEOUT = 10 end end end end

Christian
  • 37
  • 3
0

I got the same problem when using Chrome and used the following in my application_system_test_case.rb:

class Selenium::WebDriver::Service
  remove_const(:SOCKET_LOCK_TIMEOUT)
  SOCKET_LOCK_TIMEOUT = 120
end
donV
  • 1,091
  • 7
  • 15