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
2 changes: 2 additions & 0 deletions docs/api/fiber.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ app.Listen(":8080", fiber.ListenConfig{
| <Reference id="ShutdownTimeout">ShutdownTimeout</Reference> | `time.Duration` | Specifies the maximum duration to wait for the server to gracefully shutdown. When the timeout is reached, the graceful shutdown process is interrupted and forcibly terminated, and the `context.DeadlineExceeded` error is passed to the `OnPostShutdown` callback. Set to 0 to disable the timeout and wait indefinitely. | `10 * time.Second` |
| <Reference id="listeneraddrfunc">ListenerAddrFunc</Reference> | `func(addr net.Addr)` | Allows accessing and customizing `net.Listener`. | `nil` |
| <Reference id="listenernetwork">ListenerNetwork</Reference> | `string` | Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "unix" (Unix Domain Sockets). WARNING: When prefork is set to true, only "tcp4" and "tcp6" can be chosen. | `tcp4` |
| <Reference id="preforkrecoverinterval">PreforkRecoverInterval</Reference> | `time.Duration` | Delays the respawn of a crashed child process by this duration. Only applies when prefork is enabled. | `0` (respawn immediately) |
| <Reference id="preforkrecoverthreshold">PreforkRecoverThreshold</Reference> | `int` | Defines the maximum number of child process restarts after crashes before the prefork master exits with an error. Only applies when prefork is enabled. | `max(1, runtime.GOMAXPROCS(0) / 2)` |
| <Reference id="preforkshutdowngraceperiod">PreforkShutdownGracePeriod</Reference> | `time.Duration` | How long the prefork master waits for child processes to exit after SIGTERM before sending SIGKILL during shutdown. On Windows children are always killed immediately. Only applies when prefork is enabled. | `5 * time.Second` |
| <Reference id="preforklogger">PreforkLogger</Reference> | `PreforkLogger` | Sets a custom logger for the prefork process manager. Only applies when prefork is enabled. | Fiber logger |
| <Reference id="unixsocketfilemode">UnixSocketFileMode</Reference> | `os.FileMode` | FileMode to set for Unix Domain Socket (ListenerNetwork must be "unix") | `0770` |
| <Reference id="tlsconfigfunc">TLSConfigFunc</Reference> | `func(tlsConfig *tls.Config)` | Allows customizing `tls.Config` as you want. Ignored when `TLSConfig` is set. | `nil` |
Expand Down
14 changes: 14 additions & 0 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ type ListenConfig struct {
// Default: 10 * time.Second
ShutdownTimeout time.Duration `json:"shutdown_timeout"`

// PreforkRecoverInterval delays the respawn of a crashed child process by this
// duration. This only applies when EnablePrefork is true.
//
// Default: 0 (respawn immediately)
PreforkRecoverInterval time.Duration `json:"prefork_recover_interval"`

// PreforkShutdownGracePeriod is how long the prefork master waits for child
// processes to exit after SIGTERM before sending SIGKILL during shutdown.
// On Windows children are always killed immediately. This only applies when
// EnablePrefork is true.
//
// Default: 5 * time.Second
PreforkShutdownGracePeriod time.Duration `json:"prefork_shutdown_grace_period"`

// FileMode to set for Unix Domain Socket (ListenerNetwork must be "unix")
//
// Default: 0770
Expand Down
12 changes: 7 additions & 5 deletions prefork.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ func (app *App) prefork(addr string, tlsConfig *tls.Config, cfg *ListenConfig) e
}

p := &prefork.Prefork{
Network: cfg.ListenerNetwork,
Reuseport: true,
RecoverThreshold: recoverThreshold,
Logger: logger,
OnMasterDeath: func() { os.Exit(1) }, //nolint:revive // Exiting child process is intentional
Network: cfg.ListenerNetwork,
Reuseport: true,
RecoverThreshold: recoverThreshold,
RecoverInterval: cfg.PreforkRecoverInterval,
ShutdownGracePeriod: cfg.PreforkShutdownGracePeriod,
Logger: logger,
OnMasterDeath: func() { os.Exit(1) }, //nolint:revive // Exiting child process is intentional
}

// Use test command producer if in test mode
Expand Down
2 changes: 2 additions & 0 deletions prefork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func Test_App_Prefork_Master_Process(t *testing.T) {
// Use low threshold for fast test execution.
cfg := listenConfigDefault()
cfg.PreforkRecoverThreshold = 1
cfg.PreforkRecoverInterval = 10 * time.Millisecond
cfg.PreforkShutdownGracePeriod = 100 * time.Millisecond
err := app.prefork(":0", nil, &cfg)
require.ErrorIs(t, err, prefork.ErrOverRecovery)

Comment thread
ReneWerner87 marked this conversation as resolved.
Expand Down
Loading