Skip to content

Commit ce7a92e

Browse files
wtnclaude
andauthored
Close stdin before terminating a timed-out memory leak child (#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. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent fe302aa commit ce7a92e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎lib/core_assertions.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,12 @@ def assert_no_memory_leak(args, prepare, code, message=nil, limit: 2.0, rss: fal
324324
end
325325
rescue Timeout::Error
326326
timed_out = Time.now
327+
in_p.close
327328
status = begin
328329
EnvUtil.terminate(pid, opt.fetch(:signal, :TERM), opt[:pgroup], opt.fetch(:reprieve, 1))
329330
rescue Errno::ESRCH, Errno::ECHILD
330331
warn "child not found: #{pid}: #$!"
331332
end
332-
in_p.close
333333
end
334334
stdout = out_reader.value
335335
if timed_out

0 commit comments

Comments
 (0)