mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 08:25:20 +08:00
[ruby/test-unit-ruby-core] Close stdin before terminating a
timed-out memory leak child (https://github.com/ruby/test-unit-ruby-core/pull/37) * Close stdin before terminating a timed-out memory leak child With a sample range, assert_no_memory_leak keeps the child's stdin open, and the child's ensure clause reads a "continue" line from it after each sample. When the timeout fires while the child is running the sampled code, EnvUtil.terminate sends SIGTERM, and the child's ensure clause then blocks reading stdin, which was closed only after terminate returned. SIGTERM cannot end the child, so terminate escalates to SIGABRT and then waits for the aborted child without a time limit. On ruby/ruby's YJIT macOS CI jobs the child sometimes did not exit after the RUBY_ON_BUG core dump, and the test worker hung until the runner killed it 20 minutes later. In other runs the test passed but left a crash report for the child. Close stdin first. The child's read then returns nil, and its ensure clause breaks out of the sample loop. The break discards the SignalException raised by SIGTERM, so the child exits with status 0. If SIGTERM arrives before the child reaches the sample loop, the child still dies from SIGTERM. The existing timeout test now also checks that the child exited normally or by SIGTERM. https://github.com/ruby/test-unit-ruby-core/commit/ce7a92e724 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5167808893
commit
b77c9f32dc
1 file changed
+1
-1
@@ -324,12 +324,12 @@ module Test
|
||||
end
|
||||
rescue Timeout::Error
|
||||
timed_out = Time.now
|
||||
in_p.close
|
||||
status = begin
|
||||
EnvUtil.terminate(pid, opt.fetch(:signal, :TERM), opt[:pgroup], opt.fetch(:reprieve, 1))
|
||||
rescue Errno::ESRCH, Errno::ECHILD
|
||||
warn "child not found: #{pid}: #$!"
|
||||
end
|
||||
in_p.close
|
||||
end
|
||||
stdout = out_reader.value
|
||||
if timed_out
|
||||
|
||||
Reference in new issue
Block a user