Repository navigation
Close stdin before terminating a timed-out memory leak child - #37
Merged
Merged
Conversation
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>
wtn
marked this pull request as ready for review
October 26, 2026 04:21
Member
|
I appreciate the |
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Oct 27, 2026
timed-out memory leak child (ruby/test-unit-ruby-core#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. ruby/test-unit-ruby-core@ce7a92e724 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Thank you! 👏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
test_assert_no_memory_leak_applies_timeout_to_sample_rangeintermittently hangs ruby/ruby's YJIT macOS CI jobs (ruby/ruby master, ruby/ruby#19517).When the timeout fires during a sample,
EnvUtil.terminatesends SIGTERM, but the child'sensureclause then blocks reading "continue" from stdin, which is closed only afterterminatereturns.terminateescalates to SIGABRT and waits without a time limit, and on CI the aborted child sometimes never exits.Closing stdin first makes
getsreturn nil, so the child breaks out of the sample loop and exits. The timeout test now checks that the child exited 0 or by SIGTERM; before the fix it was killed by SIGABRT.