Skip to content

Commit

Permalink
Kill PTY I/O thread when we are done with it (#497)
Browse files Browse the repository at this point in the history
Sometimes the PTY slave can be closed, causing an unhandled exception in
the thread which is calling `master.read` (socket closed).

This change kills the thread before this happens.

Related to rails/spring#396
 (since this exception was causing Spring to hang)
  • Loading branch information
misterbyrne authored and jonleighton committed Nov 13, 2016
1 parent 07941cc commit d0dd8ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,11 @@ def print_exception(stream, error)
def with_pty
PTY.open do |master, slave|
[STDOUT, STDERR, STDIN].each { |s| s.reopen slave }
Thread.new { master.read }
reader_thread = Spring.failsafe_thread { master.read }
begin
yield
ensure
reader_thread.kill
reset_streams
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/spring/test/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ def self.omg
assert_success app.spring_test_command
end

test "app gets reloaded even with abort_on_exception=true" do
assert_success app.spring_test_command
File.write(app.path("config/initializers/thread_config.rb"), "Thread.abort_on_exception = true")

app.await_reload
assert_success app.spring_test_command
end

test "app recovers when a boot-level error is introduced" do
config = app.application_config.read

Expand Down

0 comments on commit d0dd8ba

Please sign in to comment.