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

Allow to configure boot and connect timeout #712

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions lib/spring/client/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ module Spring
module Client
class Run < Command
FORWARDED_SIGNALS = %w(INT QUIT USR1 USR2 INFO WINCH) & Signal.list.keys
CONNECT_TIMEOUT = 1
BOOT_TIMEOUT = 20

attr_reader :server

Expand Down Expand Up @@ -74,7 +72,7 @@ def boot_server
env.socket_path.unlink if env.socket_path.exist?

pid = Process.spawn(server_process_env, env.server_command, out: File::NULL)
timeout = Time.now + BOOT_TIMEOUT
timeout = Time.now + Spring.boot_timeout

@server_booted = true

Expand All @@ -85,7 +83,7 @@ def boot_server
exit status.exitstatus
elsif Time.now > timeout
$stderr.puts "Starting Spring server with `#{env.server_command}` " \
"timed out after #{BOOT_TIMEOUT} seconds"
"timed out after #{Spring.boot_timeout} seconds"
exit 1
end

Expand Down Expand Up @@ -122,7 +120,7 @@ def stop_server
end

def verify_server_version
unless IO.select([server], [], [], CONNECT_TIMEOUT)
unless IO.select([server], [], [], Spring.connect_timeout)
raise "Error connecting to Spring server"
end

Expand Down Expand Up @@ -151,7 +149,7 @@ def connect_to_application(client)
server.send_io client
send_json server, "args" => args, "default_rails_env" => default_rails_env, "spawn_env" => spawn_env, "reset_env" => reset_env

if IO.select([server], [], [], CONNECT_TIMEOUT)
if IO.select([server], [], [], Spring.connect_timeout)
server.gets or raise CommandNotFound
else
raise "Error connecting to Spring server"
Expand Down
5 changes: 4 additions & 1 deletion lib/spring/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require "spring/errors"

module Spring
@connect_timeout = 5
@boot_timeout = 20

class << self
attr_accessor :application_root
attr_accessor :application_root, :connect_timeout, :boot_timeout
attr_writer :quiet

def gemfile
Expand Down
2 changes: 1 addition & 1 deletion test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def exec_name
test "server boot timeout" do
app.env["SPRING_SERVER_COMMAND"] = "sleep 1"
File.write("#{app.spring_client_config}", %(
Spring::Client::Run.const_set(:BOOT_TIMEOUT, 0.1)
Spring.boot_timeout = 0.1
))

assert_failure "bin/rails runner ''", stderr: "timed out"
Expand Down
Loading