Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/async/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ def process_fork
@children = nil
@selector = nil
@timers = nil
@blocked = 0

# Close the scheduler:
Fiber.set_scheduler(nil)
Expand Down
4 changes: 4 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

## Unreleased

- Fixed scheduler cleanup after forking while other fibers are blocked.

## v2.43.0

- Propagate cancellation causes through task trees so child tasks observe the original cancellation cause.
Expand Down
23 changes: 23 additions & 0 deletions test/process/fork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,28 @@
Process.waitpid(pid) if pid
end
end

it "can fork while another fiber is blocked" do
r, w = IO.pipe
queue = Thread::Queue.new

Async do |task|
blocked_task = task.async do
queue.pop
end

pid = Process.fork do
# Child process:
w.write("hello")
end

# Parent process:
w.close
expect(r.read).to be == "hello"
ensure
blocked_task&.stop
Process.waitpid(pid) if pid
end
end
end
end
Loading