diff --git a/activesupport/lib/active_support/fork_tracker.rb b/activesupport/lib/active_support/fork_tracker.rb index cb004f432e4..75cf5e42c7e 100644 --- a/activesupport/lib/active_support/fork_tracker.rb +++ b/activesupport/lib/active_support/fork_tracker.rb @@ -36,6 +36,7 @@ module ActiveSupport def hook! ::Object.prepend(CoreExtPrivate) + ::Kernel.prepend(CoreExtPrivate) ::Kernel.singleton_class.prepend(CoreExt) ::Process.singleton_class.prepend(CoreExt) end diff --git a/activesupport/test/fork_tracker_test.rb b/activesupport/test/fork_tracker_test.rb index 990cafba681..af25f950e86 100644 --- a/activesupport/test/fork_tracker_test.rb +++ b/activesupport/test/fork_tracker_test.rb @@ -172,4 +172,39 @@ class ForkTrackerTest < ActiveSupport::TestCase ensure ActiveSupport::ForkTracker.unregister(handler) end + + def test_basic_object_with_kernel_fork + read, write = IO.pipe + called = false + + handler = ActiveSupport::ForkTracker.after_fork do + called = true + write.write "forked" + end + + klass = Class.new(BasicObject) do + include ::Kernel + def fark(&block) + fork(&block) + end + end + + object = klass.new + assert_not object.respond_to?(:fork) + pid = object.fark do + read.close + write.close + exit! + end + + write.close + + Process.waitpid(pid) + assert_equal "forked", read.read + read.close + + assert_not called + ensure + ActiveSupport::ForkTracker.unregister(handler) + end end