Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix random timeouts during Server#boot #920

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/capybara/server.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def ports
def initialize(app, port=Capybara.server_port) def initialize(app, port=Capybara.server_port)
@app = app @app = app
@middleware = Middleware.new(@app) @middleware = Middleware.new(@app)
@server_thread = nil # supress warnings
@port = port @port = port
@port ||= Capybara::Server.ports[@app.object_id] @port ||= Capybara::Server.ports[@app.object_id]
@port ||= find_available_port @port ||= find_available_port
Expand All @@ -55,8 +54,6 @@ def host
end end


def responsive? def responsive?
return false if @server_thread && @server_thread.join(0)

res = Net::HTTP.start(host, @port) { |http| http.get('/__identify__') } res = Net::HTTP.start(host, @port) { |http| http.get('/__identify__') }


if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection) if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
Expand All @@ -70,11 +67,11 @@ def boot
unless responsive? unless responsive?
Capybara::Server.ports[@app.object_id] = @port Capybara::Server.ports[@app.object_id] = @port


@server_thread = Thread.new do server_thread = Thread.new do
Capybara.server.call(@middleware, @port) Capybara.server.call(@middleware, @port)
end end


Timeout.timeout(60) { @server_thread.join(0.1) until responsive? } Timeout.timeout(60) { server_thread.join(0.1) until responsive? }
end end
rescue TimeoutError rescue TimeoutError
raise "Rack application timed out during boot" raise "Rack application timed out during boot"
Expand Down