Skip to content

feat(prefork): delegate to fasthttp/prefork to eliminate code duplication#4210

Draft
ReneWerner87 wants to merge 21 commits intomainfrom
prefork_optimization
Draft

feat(prefork): delegate to fasthttp/prefork to eliminate code duplication#4210
ReneWerner87 wants to merge 21 commits intomainfrom
prefork_optimization

Conversation

@ReneWerner87
Copy link
Copy Markdown
Member

@ReneWerner87 ReneWerner87 commented Apr 11, 2026

Summary

Replaces previous PR #4037 (accidentally merged via branch tracking misconfiguration).

  • Replace Fiber's own prefork implementation with fasthttp's prefork package
  • Eliminate ~100 lines of duplicated process management logic
  • Add PreforkRecoverThreshold to ListenConfig for configurable child recovery
  • Add PreforkLogger to ListenConfig for configurable prefork logging
  • IsChild() delegates to prefork.IsChild()
  • Callbacks (OnChildSpawn, OnMasterReady, OnChildRecover) integrate Fiber's hooks
  • New prefork_logger.go with PreforkLoggerInterface

Depends on

valyala/fasthttp#2180

Test plan

  • All prefork tests pass (child, master, TLS, mTLS, hooks)
  • Full fiber test suite passes (27s)
  • FastHTTP prefork tests pass (20/20)
  • gosec security scan: 0 issues

🤖 Generated with Claude Code

ReneWerner87 and others added 7 commits April 11, 2026 20:09
…tion

Replace Fiber's own prefork implementation with fasthttp's prefork package.
This eliminates duplicated process management logic and adds new features:

- IsChild() now delegates to prefork.IsChild()
- Master process uses fasthttp's recovery loop (RecoverThreshold)
- Callbacks (OnChildSpawn, OnMasterReady, OnChildRecover) integrate
  Fiber's hooks system (OnFork, OnListen, startup message)
- CommandProducer enables clean test injection (replaces testPreforkMaster)
- OnMasterDeath replaces Fiber's watchMaster (now in fasthttp)
- New PreforkRecoverThreshold field in ListenConfig
- prefork_logger.go adapts Fiber's logger to fasthttp's Logger interface
- go.mod uses replace directive for local fasthttp development

Code reduction: ~200 lines of process management removed from Fiber.
All existing tests adapted for recovery behavior (ErrOverRecovery).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Ensures deterministic and fast execution regardless of GOMAXPROCS count.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use github.com/ReneWerner87/fasthttp@2802b1a (prefork_optimization branch)
instead of local ../fasthttp path, so CI and other developers can resolve
the dependency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Includes fix for ListenAndServeTLS parameter order preservation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- prefork_logger.go: use grouped import declaration
- prefork.go: rename unused 'files' parameter to '_'
- prefork.go: wrap external errors from cmd.Start() and ListenAndServe()

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Move windowsOS constant to constants.go (global consts file)
- Make prefork logger configurable via ListenConfig.PreforkLogger
- Define PreforkLoggerInterface for custom logger implementations
- Use logger.Printf instead of direct log.Warnf in OnChildRecover
- Remove unused log import from prefork.go

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 11, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6009b9bf-5d8d-4c13-bf91-41e254d87027

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch prefork_optimization

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the preforking mechanism by delegating process management to the fasthttp/prefork package, simplifying the internal implementation and adding support for recovery thresholds and custom loggers. Feedback highlights a security and maintenance risk regarding the use of a personal fork for fasthttp, a bug in the test command producer that starts processes prematurely, and a logic issue where the default recovery threshold could be zero on single-core systems.

Comment thread go.mod Outdated
Comment thread prefork.go
Comment thread prefork.go Outdated
…tems

runtime.GOMAXPROCS(0)/2 yields 0 on single-core, disabling recovery.
Use max(1, ...) to guarantee at least one recovery attempt.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 12, 2026

Codecov Report

❌ Patch coverage is 92.10526% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.28%. Comparing base (6c19f48) to head (9c9fc62).
⚠️ Report is 166 commits behind head on main.

Files with missing lines Patch % Lines
prefork.go 91.66% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4210      +/-   ##
==========================================
+ Coverage   91.16%   91.28%   +0.11%     
==========================================
  Files         123      127       +4     
  Lines       11855    12321     +466     
==========================================
+ Hits        10808    11247     +439     
- Misses        659      672      +13     
- Partials      388      402      +14     
Flag Coverage Δ
unittests 91.28% <92.10%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ReneWerner87 and others added 6 commits April 13, 2026 08:39
Includes lint fixes and review feedback for CommandProducer validation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
OnChildRecover no longer returns an error (simplified API).
Update fasthttp fork reference to 9758f93.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
OnChildRecover now receives both the crashed and replacement PID.
OnFork hooks for recovered children are handled by OnChildSpawn
which fasthttp now calls for recoveries too.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Includes zombie process fix and lifecycle integration test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 4ad12cd Previous: dd8ec01 Ratio
Benchmark_Ctx_Cookie (github.com/gofiber/fiber/v3) 189.4 ns/op 0 B/op 0 allocs/op 122 ns/op 0 B/op 0 allocs/op 1.55
Benchmark_Ctx_Cookie (github.com/gofiber/fiber/v3) - ns/op 189.4 ns/op 122 ns/op 1.55

This comment was automatically generated by workflow using github-action-benchmark.

Mirrors fasthttp PR #2180 which made OnChildRecover symmetric with the
other lifecycle hooks. Fiber's recovery callback only logs and so simply
returns nil; future callers can short-circuit recovery by returning an
error from this hook.

Also renames the local pid parameters to oldPID/newPID per Go initialism
convention.
@ReneWerner87 ReneWerner87 self-assigned this May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant