{"id":"057e54f229139ff6","repo":"gofiber/fiber","slug":"shutdown-server-is-not-running","errorCode":null,"errorMessage":"shutdown: server is not running","messagePattern":"shutdown: server is not running","errorType":"exception","errorClass":"ErrNotRunning","httpStatus":null,"severity":"error","filePath":"error.go","lineNumber":18,"sourceCode":"package fiber\n\nimport (\n\t\"encoding/json\"\n\t\"errors\"\n\n\t\"github.com/gofiber/schema\"\n)\n\n// Wrap and return this for unreachable code if panicking is undesirable (i.e., in a handler).\n// Unexported because users will hopefully never need to see it.\nvar errUnreachable = errors.New(\"fiber: unreachable code, please create an issue at github.com/gofiber/fiber\")\n\n// General errors\nvar (\n\tErrGracefulTimeout = errors.New(\"shutdown: graceful timeout has been reached, exiting\")\n\t// ErrNotRunning indicates that a Shutdown method was called when the server was not running.\n\tErrNotRunning = errors.New(\"shutdown: server is not running\")\n\t// ErrHandlerExited is returned by App.Test if a handler panics or calls runtime.Goexit().\n\tErrHandlerExited = errors.New(\"runtime.Goexit() called in handler or server panic\")\n\t// ErrNoViewEngineConfigured indicates that a helper requiring a view engine was invoked without one configured.\n\tErrNoViewEngineConfigured = errors.New(\"fiber: no view engine configured\")\n\t// ErrAutoCertWithCertFile indicates AutoCertManager cannot be used with CertFile/CertKeyFile.\n\tErrAutoCertWithCertFile = errors.New(\"tls: AutoCertManager cannot be combined with CertFile/CertKeyFile\")\n)\n\n// Fiber redirection errors\nvar (\n\tErrRedirectBackNoFallback = NewError(StatusInternalServerError, \"Referer not found, you have to enter fallback URL for redirection.\")\n)\n\n// Range errors\nvar (\n\t// ErrRangeMalformed is returned for a syntactically invalid Range header,\n\t// which RFC 9110 Section 14.2 allows a server to reject; it carries a\n\t// 400 Bad Request status so propagating it does not surface as a 500.","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/error.go#L1-L36","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n// (main exits without Listen, signal handler calls Shutdown immediately)\ngo func() { _ = app.Shutdown() }()\n\n// after\ngo func() { _ = app.Listen(\":3000\") }()\n// ... wait for startup ...\nif err := app.Shutdown(); err != nil && !errors.Is(err, fiber.ErrNotRunning) {\n    log.Printf(\"shutdown: %v\", err)\n}","handlingStrategy":"validation","validationCode":"// Only shut down if the server actually started.\nif app.Server() != nil {\n    _ = app.Shutdown()\n}","typeGuard":null,"tryCatchPattern":"if err := app.Shutdown(); err != nil && !errors.Is(err, fiber.ErrNotRunning) {\n    log.Printf(\"shutdown failed: %v\", err)\n}","preventionTips":["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."],"tags":["shutdown","server","lifecycle","fiber"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}