Skip to content

Commit 6bba044

Browse files
committed
Merge PR #647
2 parents 6ce5d89 + 1c15dcd commit 6bba044

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Next Release
22

3+
* Fix bug which makes rails consoles to hang at exit when multiple of them are open (#647)
4+
35
## 3.0.0
46

57
* Require applications to have reloading enabled in the managed environments.

lib/spring/application.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def initialize(manager, original_env, spring_env = Env.new)
1212
@spring_env = spring_env
1313
@mutex = Mutex.new
1414
@waiting = Set.new
15+
@clients = Set.new
1516
@preloaded = false
1617
@state = :initialized
1718
@interrupt = IO.pipe
@@ -149,6 +150,8 @@ def serve(client)
149150
log "got client"
150151
manager.puts
151152

153+
@clients << client
154+
152155
_stdout, stderr, _stdin = streams = 3.times.map { client.recv_io }
153156
[STDOUT, STDERR, STDIN].zip(streams).each { |a, b| a.reopen(b) }
154157

@@ -176,6 +179,10 @@ def serve(client)
176179
end
177180

178181
pid = fork {
182+
# Make sure to close other clients otherwise their graceful termination
183+
# will be impossible due to reference from this fork.
184+
@clients.select { |c| c != client }.each(&:close)
185+
179186
Process.setsid
180187
IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
181188
trap("TERM", "DEFAULT")

0 commit comments

Comments
 (0)