Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

localhost hardcoded in base.rb #285

Closed
maxdoubt opened this issue May 25, 2017 · 5 comments
Closed

localhost hardcoded in base.rb #285

maxdoubt opened this issue May 25, 2017 · 5 comments

Comments

@maxdoubt
Copy link

maxdoubt commented May 25, 2017

i run jasmine in docker, and am having an issue where localhost returns Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for "localhost" port 58000.

Would binding to 0.0.0.0, or perhaps have this available as an instance variable that could be easily set, be an appropriate fix? See related code in lib/base.rb below:

  def self.wait_for_listener(port, name = "required process", seconds_to_wait = 20)
    time_out_at = Time.now + seconds_to_wait
    until server_is_listening_on "localhost", port
      sleep 0.1
      puts "Waiting for #{name} on #{port}..."
      raise "#{name} didn't show up on port #{port} after #{seconds_to_wait} seconds." if Time.now > time_out_at
    end
  end
@slackersoft
Copy link
Member

This sounds like a duplicate of #269 which hasn't been merged yet due to the issues mentioned there. I'd be happy to re-review that, or review a new pull request to fix this as discussed in #269.

Thanks for using Jasmine!

@ncreuschling
Copy link

ncreuschling commented May 29, 2017

So my colleague and I stumbled upon the same issue (jasmine with phantomjs in Docker container). We played around a little bit, maybe this is useful to the discussion at hand:

When you add a sleep(1) before the call to wait_for_listener (in ci_runnner.rb around line 34) it works.

t = @thread.new do
  server.start
 end

t.abort_on_exception = true
sleep(1)
Jasmine::wait_for_listener(config.port(:ci), 'jasmine server')

Another way is to add Errno::EADDRNOTAVAIL to the list of known, rescued exceptions in method self.server_is_listening_on(hostname, port) in base.rb:

def self.server_is_listening_on(hostname, port)
  require 'socket'
  begin
    socket = TCPSocket.open(hostname, port)
  rescue Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::EAFNOSUPPORT, Errno::EADDRNOTAVAIL
    return false
  end
  socket.close
  true
end

We would like to see the latter idea released as a hotfix.

@ncreuschling
Copy link

ncreuschling commented May 31, 2017

@maxdoubt Do you have any idea if #286 will work for your problem as well?

@slackersoft Is is possible for you to please comment on #286 whether you are willing to release an official version any time soon. I hope this doesn't sound too annoying.

@maxdoubt
Copy link
Author

@ncreuschling I'll try and test when i get a free moment (within the week). This docker issue only appeared in our CI tool and I just threw a monkey patch at it to override localhost with 0.0.0.0, so i'll have to figure out how to recreate this locally... stay tuned

@ncreuschling
Copy link

ncreuschling commented May 31, 2017

Thank you for your reply. This sound exactly like the issue we face (Docker, Jenkins, jasmine). I am looking forward to your experience.

slackersoft pushed a commit that referenced this issue Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants