Skip to content

Commit c5ee45f

Browse files
Improve handling of Process.fork on Ruby 4+.
1 parent 1c41e47 commit c5ee45f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

lib/async/fork_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _fork(&block)
2626
private_constant :ForkHandler
2727

2828
# Hook into Process._fork to handle fork events automatically:
29-
unless (Fiber.const_get(:SCHEDULER_PROCESS_FORK) rescue false)
29+
unless RUBY_VERSION > "4"
3030
::Process.singleton_class.prepend(ForkHandler)
3131
end
3232
end

lib/async/scheduler.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,17 +646,13 @@ def timeout_after(duration, exception, message, &block)
646646
end
647647
end
648648

649-
# Handle fork in the child process. This method is called automatically when `Process.fork` is invoked.
649+
# Handle fork in the child process. This method is called automatically when `Process.fork` is invoked on Ruby versions < 4 and cleans up the scheduler state. On Ruby 4+, the scheduler is automatically cleaned up by the Ruby runtime.
650650
#
651651
# The child process starts with a clean slate - no scheduler is set. Users can create a new scheduler if needed.
652652
#
653653
# @public Since *Async v2.35*.
654654
def process_fork
655-
if profiler = @profiler
656-
@profiler = nil
657-
profiler.stop
658-
end
659-
655+
@profiler = nil
660656
@children = nil
661657
@selector = nil
662658
@timers = nil

releases.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Improved handling of `Process.fork` on Ruby 4+.
6+
37
## v2.35.1
48

59
- Fix incorrect handling of spurious wakeups in `Async::Promise#wait`, which could lead to premature (incorrect) resolution of the promise.

0 commit comments

Comments
 (0)