Bug #14929
closed[PATCH] thread.c (do_select): fix leak on exception
Description
thread.c (do_select): fix leak on exception
When do_select is interrupted and raise happens from
RUBY_VM_CHECK_INTS_BLOCKING, the original FD sets we copied
do not get freed, leading to a memory leak. Wrap up all the
FD sets into a Ruby object to ensure the GC can release an
allocations made for rb_fdset_t.
This leak existed since Ruby 2.0.0 (r36430)
I found this bug because I was tracking down a problem
while working on timer-thread elimination.
Files
Updated by normalperson (Eric Wong) over 6 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r64007.
thread.c (do_select): fix leak on exception
When do_select is interrupted and raise happens from
RUBY_VM_CHECK_INTS_BLOCKING, the original FD sets we copied
do not get freed, leading to a memory leak. Wrap up all the
FD sets into a Ruby object to ensure the GC can release an
allocations made for rb_fdset_t.
This leak existed since Ruby 2.0.0 (r36430)
[Bug #14929]
Updated by usa (Usaku NAKAMURA) over 6 years ago
- Backport changed from 2.3: REQUIRED, 2.4: REQUIRED, 2.5: REQUIRED to 2.3: REQUIRED, 2.4: DONE, 2.5: REQUIRED
ruby_2_4 r64561 merged revision(s) 64007,64019,64020.
Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago
- Backport changed from 2.3: REQUIRED, 2.4: DONE, 2.5: REQUIRED to 2.3: REQUIRED, 2.4: DONE, 2.5: DONE
ruby_2_5 r64605 merged revision(s) 64007,64019,64020.
Updated by jaruga (Jun Aruga) about 6 years ago
Could you backport below commits for test/ruby/test_io.rb#test_select_leak from ruby_2_5 or trunk to ruby_2_4 branch?
ruby_2_5 branch¶
$ git diff ruby_2_4..ruby_2_5 test/ruby/test_io.rb
...
def test_select_leak
- assert_no_memory_leak([], <<-"end;", <<-"end;", rss: true, timeout: 60)
+ assert_no_memory_leak([], <<-"end;", <<-"end;", rss: true, timeout: 240)
r, w = IO.pipe
rset = [r]
wset = [w]
@@ -3562,6 +3755,7 @@ def test_select_leak
Thread.pass until th.stop?
th.kill
th.join
+ GC.start
end
end;
end
trunk branch¶
$ git diff ruby_2_4..trunk test/ruby/test_io.rb
...
def test_select_leak
- assert_no_memory_leak([], <<-"end;", <<-"end;", rss: true, timeout: 60)
+ # avoid malloc arena explosion from glibc and jemalloc:
...
end
+ th.kill
+ th.join
end;
end
I faced this issue when building ruby-2.4 on on Fedora multi archs environment.
I think that this also can fix on rubyci ruby_2.4 test.
https://rubyci.org/logs/rubyci.s3.amazonaws.com/freebsd11zfs/ruby-2.4/log/20181112T102145Z.fail.html.gz
Thank you!