14

I got an error using Selenium webdrive. My platform is macOS. This is my exception log.

ruby-1.9.2-p0 > Selenium::WebDriver.for :firefox
Selenium::WebDriver::Error::WebDriverError: unable to bind to locking port 7054 within 45 seconds
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/firefox/socket_lock.rb:48:in `lock'
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/firefox/socket_lock.rb:29:in `locked'
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/firefox/bridge.rb:21:in `initialize'
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/common/driver.rb:38:in `new'
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/common/driver.rb:38:in `for'
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver.rb:51:in `for'
 from (irb):8
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in `start'
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in `start'
 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:23:in `<top (required)>'
 from script/rails:6:in `require'
 from script/rails:6:in `<main>'

My Firefox path is the default path. How did this happen?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Small Wolf
  • 283
  • 4
  • 17

5 Answers5

20

WebDriver uses port 7054 (the "locking port") as a mutex to ensure that we don't launch two Firefox instances at the same time. Each new instance you create will wait for the mutex before starting the browser, then release it as soon as the browser is open.

So this could indeed be a resource issue - a previously created driver is taking more than 45 seconds to launch and is holding on to the lock for that time.

If this seems unlikely in your case it would be interesting to know what process is holding the lock. Try running lsof -i TCP:7054 in the 45 seconds before it times out.

Running ruby with -d (or setting $DEBUG = true) will also provide some useful info for debugging this further.

jarib
  • 6,028
  • 1
  • 24
  • 27
  • Thanks! This helped me fix the problem somehow I had a process hogging up 75% CPU listening to this port (maybe another instance of selenium-webdriver that didn't stop gracefully). Killing that process let firefox start up just like normal. – nzifnab Jun 06 '11 at 22:07
  • Thanks. Can you please tell me what is a locking port and mutex ? – HelloWorldNoMore Apr 13 '16 at 18:26
6

I did lsof -i TCP:7054 and found the corresponding process_id, and then finally killed the given process withkill -9 process_id

And then tried the test again, and it did worked :)

kxhitiz
  • 1,909
  • 4
  • 19
  • 25
  • This totally worked for me, found out I had another process running on that port, which was a remnant from a past project I had worked on. – Evolve Aug 24 '11 at 05:24
  • Just make sure you understand what process is holding the port before killing it! For example, in my case the port was being used by my remote connection. Kill -9 on that process would have been a bad idea! – SamStephens Jan 19 '15 at 22:21
1

I was getting this as well and running "lsof -i TCP:7054" and killing the offending pid fixed my issue also.

Dennis Ferguson
  • 97
  • 2
  • 10
1

I've been using cucumber + capybara + webdriver + parallel_tests, & i've encountered the mentioned error. To resolve the issue, i added the following to features/support/env.rb:

unless (env_no = ENV['TEST_ENV_NUMBER'].to_i).zero?
  # Standard, which is described at the parallel_tests github page
  Capybara.server_port = 8888 + env_no

  # This successfully avoids locking port error, may require less, but
  # on my 8 cores vm, this works like a charm
  sleep env_no * 10
end

U probably need to adapt the above to fit what u use, the idea is just to force a sleep time to avoid starting all firefox instances at abt the same time, where a wait of 45secs may not be enough.

ngty
  • 183
  • 6
0

I noticed that it would run on port 7054 but it was looking for it on port 7055.

bundle update did it for me

ob1
  • 1,792
  • 15
  • 20