Skip to content

Commit a0804aa

Browse files
committed
Wait for child processes when shutting down server
Should fix sporadic CI failures
1 parent 95bca40 commit a0804aa

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/spring/application_manager.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def initialize(app_env)
66
@app_env = app_env
77
@spring_env = Env.new
88
@mutex = Mutex.new
9+
@state = :running
910
end
1011

1112
def log(message)
@@ -26,6 +27,7 @@ def start
2627
end
2728

2829
def restart
30+
return if @state == :stopping
2931
start_child(true)
3032
end
3133

@@ -74,7 +76,12 @@ def run(client)
7476
end
7577

7678
def stop
77-
Process.kill('TERM', pid) if pid
79+
@state = :stopping
80+
81+
if pid
82+
Process.kill('TERM', pid)
83+
Process.wait(pid)
84+
end
7885
end
7986

8087
private

lib/spring/server.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ def set_exit_hook
9292
end
9393

9494
def shutdown
95-
@applications.values.each(&:stop)
96-
9795
[env.socket_path, env.pidfile_path].each do |path|
9896
if path.exist?
9997
path.unlink rescue nil
10098
end
10199
end
100+
101+
@applications.values.map { |a| Thread.new { a.stop } }.map(&:join)
102102
end
103103

104104
def write_pidfile

0 commit comments

Comments
 (0)