Skip to content

Commit c40f0ca

Browse files
ccutrerjonleighton
authored andcommitted
fix preloading of app with hidden pty with lots of output
if we never read from the PTY, and the app spews a lot of messages on startup, it might hang because the buffer is full
1 parent 666db7d commit c40f0ca

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/spring/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def print_exception(stream, error)
283283
def with_pty
284284
PTY.open do |master, slave|
285285
[STDOUT, STDERR, STDIN].each { |s| s.reopen slave }
286+
Thread.new { master.read }
286287
yield
287288
reset_streams
288289
end

lib/spring/test/acceptance_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ def exec_name
328328
expr = "p Kernel.private_instance_methods.include?(:raise)"
329329
assert_success %(bin/rails runner '#{expr}'), stdout: "true"
330330
end
331+
332+
test "app gets reloaded even with a ton of boot output" do
333+
File.write(app.path("config/initializers/verbose.rb"), "50.times { puts 'x' * 80 }\n")
334+
begin
335+
app.env["RAILS_ENV"] = "test"
336+
assert_success "bin/rails runner 'puts Spring.watcher.class'", stdout: "Polling"
337+
assert_app_reloaded
338+
ensure
339+
File.unlink(app.path("config/initializers/verbose.rb"))
340+
end
341+
end
331342
end
332343
end
333344
end

0 commit comments

Comments
 (0)