Module: Quonfig::ForkSafety
- Included in:
- Quonfig
- Defined in:
- lib/quonfig/client.rb
Overview
qfg-ryov: hook into Process._fork so customers using Puma’s clustered mode (or any preload/fork-worker server) don’t have to wire before_fork/on_worker_boot manually. Ruby 3.1+ routes every Kernel#fork/Process.fork call through Process._fork, so a single prepend covers them all.
Process._fork’s contract:
- Called in the parent process before the fork syscall.
- Returns 0 in the child, child's pid in the parent.
- +super+ performs the actual fork.
The parent’s view: SSE/polling/telemetry threads are torn down before the syscall so the child does not inherit a live Net::HTTP socket fd (which would corrupt both sides). The parent does NOT auto-restart —that mirrors the Puma master use case where the master process no longer serves requests after spawning workers.
Instance Method Summary collapse
Instance Method Details
#_fork ⇒ Object
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 |
# File 'lib/quonfig/client.rb', line 1032 def _fork Quonfig::Client.each_instance(&:before_fork_in_parent) pid = super Quonfig::Client.each_instance(&:after_fork_in_child) if pid.zero? pid rescue StandardError => e # Fork-hook failures must never break the customer's fork. Worst case # the child inherits dead SSE threads (the pre-qfg-ryov behavior) — # bad, but recoverable. Crashing the fork itself is not. Quonfig::Client::LOG.error "Quonfig fork hook error: #{e.class}: #{e.}" raise if pid.nil? # super never returned — propagate fork failures pid end |