gofiber/fiber · error · ErrNotRunning
shutdown: server is not running
Error message
shutdown: server is not running
What it means
ErrNotRunning (error.go:18) is returned by ShutdownWithContext (app.go:1336) when app.server is nil, i.e. the application was never started with Listen/Listener before Shutdown was called. It guards against operating on an uninitialized server and makes the missing startup explicit rather than panicking on a nil pointer dereference.
Source
Thrown at error.go:18
package fiber
import (
"encoding/json"
"errors"
"github.com/gofiber/schema"
)
// Wrap and return this for unreachable code if panicking is undesirable (i.e., in a handler).
// Unexported because users will hopefully never need to see it.
var errUnreachable = errors.New("fiber: unreachable code, please create an issue at github.com/gofiber/fiber")
// General errors
var (
ErrGracefulTimeout = errors.New("shutdown: graceful timeout has been reached, exiting")
// ErrNotRunning indicates that a Shutdown method was called when the server was not running.
ErrNotRunning = errors.New("shutdown: server is not running")
// ErrHandlerExited is returned by App.Test if a handler panics or calls runtime.Goexit().
ErrHandlerExited = errors.New("runtime.Goexit() called in handler or server panic")
// ErrNoViewEngineConfigured indicates that a helper requiring a view engine was invoked without one configured.
ErrNoViewEngineConfigured = errors.New("fiber: no view engine configured")
// ErrAutoCertWithCertFile indicates AutoCertManager cannot be used with CertFile/CertKeyFile.
ErrAutoCertWithCertFile = errors.New("tls: AutoCertManager cannot be combined with CertFile/CertKeyFile")
)
// Fiber redirection errors
var (
ErrRedirectBackNoFallback = NewError(StatusInternalServerError, "Referer not found, you have to enter fallback URL for redirection.")
)
// Range errors
var (
// ErrRangeMalformed is returned for a syntactically invalid Range header,
// which RFC 9110 Section 14.2 allows a server to reject; it carries a
// 400 Bad Request status so propagating it does not surface as a 500.View on GitHub (pinned to 9a4c7e57fe)
Solutions
- Ensure app.Listen / app.Listener has started (in its own goroutine) before calling Shutdown.
- Guard the shutdown call with a check on app.Server() != nil, or simply ignore ErrNotRunning in signal handlers.
- In tests, only call Shutdown after the server has actually started serving.
Example fix
// before
// (main exits without Listen, signal handler calls Shutdown immediately)
go func() { _ = app.Shutdown() }()
// after
go func() { _ = app.Listen(":3000") }()
// ... wait for startup ...
if err := app.Shutdown(); err != nil && !errors.Is(err, fiber.ErrNotRunning) {
log.Printf("shutdown: %v", err)
} Defensive patterns
Strategy: validation
Validate before calling
// Only shut down if the server actually started.
if app.Server() != nil {
_ = app.Shutdown()
} Try / catch
if err := app.Shutdown(); err != nil && !errors.Is(err, fiber.ErrNotRunning) {
log.Printf("shutdown failed: %v", err)
} Prevention
- Start Listen/Listener in its own goroutine before wiring shutdown to signals.
- In tests, gate shutdown behind a 'started' flag that flips after Listen begins.
- Ignore ErrNotRunning explicitly in signal handlers.
When it happens
Trigger: Calling app.Shutdown() (or ShutdownWithTimeout/ShutdownWithContext) before any app.Listen(...) or app.Listener(...) has been invoked, or calling Shutdown twice when the first call already cleared the server. Also when startup failed and the shutdown hook in the error path still runs.
Common situations: Signal handlers wired up before the listen goroutine starts, test teardown calling Shutdown on an app that never served, or a startup error that skips Listen but still triggers the shutdown path.
Related errors
- shutdown: graceful timeout has been reached, exiting
- runtime.Goexit() called in handler or server panic
- min constraint requires an argument
- max constraint requires an argument
- range constraint requires two arguments
AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04).
Data as JSON: /data/errors/057e54f229139ff6.json.
Report an issue: GitHub.