Skip to content

Commit

Permalink
🩹fix: set default ShutdownTimeout to 10s
Browse files Browse the repository at this point in the history
  • Loading branch information
ksw2000 committed Dec 4, 2024
1 parent 95b1fbc commit 436898f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/api/fiber.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ app.Listen(":8080", fiber.ListenConfig{
| <Reference id="enableprefork">EnablePrefork</Reference> | `bool` | When set to true, this will spawn multiple Go processes listening on the same port. | `false` |
| <Reference id="enableprintroutes">EnablePrintRoutes</Reference> | `bool` | If set to true, will print all routes with their method, path, and handler. | `false` |
| <Reference id="gracefulcontext">GracefulContext</Reference> | `context.Context` | Field to shutdown Fiber by given context gracefully. | `nil` |
| <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 `OnShutdownError` callback. Set to 0 (default) to disable the timeout and wait indefinitely. | `0` |
| <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 `OnShutdownError` 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). WARNING: When prefork is set to true, only "tcp4" and "tcp6" can be chosen. | `tcp4` |
| <Reference id="onshutdownerror">OnShutdownError</Reference> | `func(err error)` | Allows to customize error behavior when gracefully shutting down the server by given signal. Prints error with `log.Fatalf()` | `nil` |
Expand Down
9 changes: 5 additions & 4 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ type ListenConfig struct {

// When the graceful shutdown begins, use this field to set the timeout
// duration. If the timeout is reached, OnShutdownError will be called.
// The default value is 0, which means the timeout setting is disabled.
// Set to 0 to disable the timeout and wait indefinitely.
//
// Default: 0
// Default: 10 * time.Second
ShutdownTimeout time.Duration `json:"shutdown_timeout"`

// When set to true, it will not print out the «Fiber» ASCII art and listening address.
Expand All @@ -122,8 +122,9 @@ func listenConfigDefault(config ...ListenConfig) ListenConfig {
return ListenConfig{
ListenerNetwork: NetworkTCP4,
OnShutdownError: func(err error) {
log.Fatalf("shutdown: %v", err) //nolint:revive // It's an optipn
log.Fatalf("shutdown: %v", err) //nolint:revive // It's an option

Check warning on line 125 in listen.go

View check run for this annotation

Codecov / codecov/patch

listen.go#L125

Added line #L125 was not covered by tests
},
ShutdownTimeout: 10 * time.Second,
}
}

Expand All @@ -134,7 +135,7 @@ func listenConfigDefault(config ...ListenConfig) ListenConfig {

if cfg.OnShutdownError == nil {
cfg.OnShutdownError = func(err error) {
log.Fatalf("shutdown: %v", err) //nolint:revive // It's an optipn
log.Fatalf("shutdown: %v", err) //nolint:revive // It's an option

Check warning on line 138 in listen.go

View check run for this annotation

Codecov / codecov/patch

listen.go#L138

Added line #L138 was not covered by tests
}
}

Expand Down

0 comments on commit 436898f

Please sign in to comment.