RubyConf Taiwan 2023
Refining Fork Management: From Workarounds to `Process#_fork`

Refining Fork Management: From Workarounds to `Process#_fork`
Jian Wei-Hang • December 15, 2023 • Taipai, Taiwan

#rubyconftw 2023

Refining Fork Management: From Workarounds to `Process#_fork`

With the release of Ruby 3.1 in 2021, an enhancement arrived as Process#_fork, allowing us to override the fork method. This addition simplifies creating callbacks when forking. While there was no official method to track fork events prior to Ruby 3.1, this limitation didn't deter the community from exploring various approaches to achieve the same goal.

In the past, Rails encouraged the use of before_fork and after_fork for connection management, redis-rb ensured fork safety by storing the Process#pid in a variable, and some even used threads to track fork events.

During this session, I will delve into the backstory of _fork and explore the diverse methods the community employed for creating callbacks during forking prior to Ruby 3.1.

RubyConf Taiwan 2023

Explore all talks recorded at RubyConf Taiwan 2023
+19