From ecd2c08a4c8f9e3881d93131456d3ff066bc5de1 Mon Sep 17 00:00:00 2001 From: normal Date: Sun, 18 Feb 2018 03:00:33 +0000 Subject: thread.c (thread_join_m): handle negative timeouts correctly Users may subtract and round into negative values when using Thread#join, so clamp the timeout to zero to avoid infinite/long timeouts. Note: other methods such as Kernel#sleep and IO.select will raise on negative values, but Thread#join is an outlier *shrug* This restores Ruby 2.5 (and earlier) behavior. Fixes: r62182 (commit c915390b9530c31b4665aacf27c1adfc114f768e) ("thread.c: avoid FP for Thread#join") git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_thread.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/ruby/test_thread.rb') diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 2d84ee3a6d..921f5a01c1 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -234,6 +234,13 @@ class TestThread < Test::Unit::TestCase t = Thread.new {} assert_same t, t.join(limit), "limit=#{limit.inspect}" end + t = Thread.new { sleep } + [ -1, -0.1, RbConfig::LIMITS['FIXNUM_MIN'], RbConfig::LIMITS['INT64_MIN'], + -Float::INFINITY + ].each do |limit| + assert_nil t.join(limit), "limit=#{limit.inspect}" + end + t.kill end def test_kill_main_thread -- cgit v1.2.3