Skip to content

Commit

Permalink
Merge PR #647
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Nov 23, 2021
2 parents 6ce5d89 + 1c15dcd commit 6bba044
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next Release

* Fix bug which makes rails consoles to hang at exit when multiple of them are open (#647)

## 3.0.0

* Require applications to have reloading enabled in the managed environments.
Expand Down
7 changes: 7 additions & 0 deletions lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(manager, original_env, spring_env = Env.new)
@spring_env = spring_env
@mutex = Mutex.new
@waiting = Set.new
@clients = Set.new
@preloaded = false
@state = :initialized
@interrupt = IO.pipe
Expand Down Expand Up @@ -149,6 +150,8 @@ def serve(client)
log "got client"
manager.puts

@clients << client

_stdout, stderr, _stdin = streams = 3.times.map { client.recv_io }
[STDOUT, STDERR, STDIN].zip(streams).each { |a, b| a.reopen(b) }

Expand Down Expand Up @@ -176,6 +179,10 @@ def serve(client)
end

pid = fork {
# Make sure to close other clients otherwise their graceful termination
# will be impossible due to reference from this fork.
@clients.select { |c| c != client }.each(&:close)

Process.setsid
IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
trap("TERM", "DEFAULT")
Expand Down

0 comments on commit 6bba044

Please sign in to comment.