Skip to content

Commit bf363c3

Browse files
committed
Kill PTY I/O thread when we are done with it
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 #396 (since this exception was causing Spring to hang)
1 parent f350d8a commit bf363c3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: lib/spring/application.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,11 @@ def print_exception(stream, error)
295295
def with_pty
296296
PTY.open do |master, slave|
297297
[STDOUT, STDERR, STDIN].each { |s| s.reopen slave }
298-
Thread.new { master.read }
298+
reader_thread = Spring.failsafe_thread { master.read }
299299
begin
300300
yield
301301
ensure
302+
reader_thread.kill
302303
reset_streams
303304
end
304305
end

Diff for: lib/spring/test/acceptance_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ def self.omg
172172
assert_success app.spring_test_command
173173
end
174174

175+
test "app gets reloaded even with abort_on_exception=true" do
176+
assert_success app.spring_test_command
177+
File.write(app.path("config/initializers/thread_config.rb"), "Thread.abort_on_exception = true")
178+
179+
app.await_reload
180+
assert_success app.spring_test_command
181+
end
182+
175183
test "app recovers when a boot-level error is introduced" do
176184
config = app.application_config.read
177185

0 commit comments

Comments
 (0)