Skip to content

Commit 2dd5d97

Browse files
committed
Prevent infinite boot loop
e3cd7e4 introduced the possibility of an infinite boot loop, where we try to restart the server, but it doesn't resolve the version mismatch (for whatever reason), so we try again... Related to #479
1 parent bec1b8e commit 2dd5d97

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
(#478)
55
* Time out after 10 seconds if starting the spring server doesn't work
66
(maybe related to #480, #479)
7+
* Prevent infinite boot loop when trying to restart the spring server
8+
due to client/server version mismatch (related to #479)
79

810
## 1.7.0
911

lib/spring/client/run.rb

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class Run < Command
1313

1414
def initialize(args)
1515
super
16-
@signal_queue = []
16+
17+
@signal_queue = []
18+
@server_booted = false
1719
end
1820

1921
def log(message)
@@ -74,6 +76,8 @@ def boot_server
7476
pid = Process.spawn(gem_env, env.server_command, out: File::NULL)
7577
timeout = Time.now + BOOT_TIMEOUT
7678

79+
@server_booted = true
80+
7781
until env.socket_path.exist?
7882
_, status = Process.waitpid2(pid, Process::WNOHANG)
7983

@@ -89,6 +93,10 @@ def boot_server
8993
end
9094
end
9195

96+
def server_booted?
97+
@server_booted
98+
end
99+
92100
def gem_env
93101
bundle = Bundler.bundle_path.to_s
94102
paths = Gem.path + ENV["GEM_PATH"].to_s.split(File::PATH_SEPARATOR)
@@ -108,13 +116,17 @@ def stop_server
108116
def verify_server_version
109117
server_version = server.gets.chomp
110118
if server_version != env.version
111-
$stderr.puts <<-ERROR
112-
There is a version mismatch between the spring client (#{env.version}) and the server (#{server_version}).
113-
Restarting to resolve.
114-
ERROR
119+
$stderr.puts "There is a version mismatch between the spring client " \
120+
"(#{env.version}) and the server (#{server_version})."
115121

116-
stop_server
117-
cold_run
122+
if server_booted?
123+
$stderr.puts "We already tried to reboot the server, but the mismatch is still present."
124+
exit 1
125+
else
126+
$stderr.puts "Restarting to resolve."
127+
stop_server
128+
cold_run
129+
end
118130
end
119131
end
120132

0 commit comments

Comments
 (0)