Project

General

Profile

Actions

Bug #21717

closed

Cleanup fiber scheduler after fork

Bug #21717: Cleanup fiber scheduler after fork

Added by noteflakes (Sharon Rosner) about 1 month ago. Updated about 1 month ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:123928]

Description

When using a fiber scheduler and forking a process, the child process "inherits" the fiber scheduler. An inherited scheduler will carry over state into the child process, and depending on the underlying event loop mechanism (e.g. epoll, kqueue, io_uring) may not work at all in the child process.

The child process also "inherits" the blocking mode of the fiber from which the fork made, so if a fork was made from a non-blocking fiber, the main fiber of the forked process will stay in non-blocking mode, which may lead to unexpected behavior. By default, each thread's main fiber is always blocking.

The proposed solution:

  • Remove the fiber scheduler from the main thread after a fork.
  • Reset the main fiber to blocking mode after a fork.

The associated PR: https://github.com/ruby/ruby/pull/15385

Updated by Dan0042 (Daniel DeLorme) about 1 month ago Actions #1 [ruby-core:123957]

Ruby already has an API for this: Process._fork

If your Fiber scheduler needs to be reset after a fork, I would recommend hooking into this.

Updated by noteflakes (Sharon Rosner) about 1 month ago Actions #2

  • Subject changed from Introduce Fiber::Scheduler#process_fork hook to Cleanup fiber scheduler after fork
  • Description updated (diff)

Updated by noteflakes (Sharon Rosner) about 1 month ago Actions #3

  • Tracker changed from Feature to Bug
  • Description updated (diff)
  • Backport set to 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN

Updated by noteflakes (Sharon Rosner) about 1 month ago Actions #4

  • Description updated (diff)

Updated by mame (Yusuke Endoh) about 1 month ago Actions #5

  • Status changed from Open to Feedback
Actions

Also available in: PDF Atom