gofiber/fiber · error · ErrHandlerExited

runtime.Goexit() called in handler or server panic

Error message

runtime.Goexit() called in handler or server panic

What it means

ErrHandlerExited (error.go:20) is returned by App.Test (app.go:1442) when the goroutine serving the test connection returns abnormally because a handler called runtime.Goexit() or panicked in a way that unwound the stack without producing a normal ServeConn result. It distinguishes a 'the handler bailed out' condition from a real HTTP/network error so test authors know to inspect handler code rather than the test plumbing.

Source

Thrown at error.go:20

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.
	ErrRangeMalformed = NewError(StatusBadRequest, "range: malformed range header string")
	// ErrRangeUnsupported is returned for a Range header whose range unit is

View on GitHub (pinned to 9a4c7e57fe)

Solutions

  1. Audit the handler under test for runtime.Goexit() calls and replace them with returned errors.
  2. Ensure fiber.Config or the recovery middleware is active so panics are recovered rather than unwinding the test goroutine.
  3. Reproduce the panic directly (without app.Test) to read the stack trace and fix the root cause.

Example fix

// before
app.Get("/exit", func(c fiber.Ctx) error {
    if bad {
        runtime.Goexit() // produces ErrHandlerExited in app.Test
    }
    return c.SendStatus(200)
})

// after
app.Get("/exit", func(c fiber.Ctx) error {
    if bad {
        return fiber.NewError(fiber.StatusBadRequest, "bad input")
    }
    return c.SendStatus(200)
})
Defensive patterns

Strategy: try-catch

Validate before calling

// Enable recovery so panics in handlers don't unwind the test goroutine.
app := fiber.New(fiber.Config{DisableDefaultErrorHandler: false})
app.Use(recoverware.New())

Try / catch

resp, err := app.Test(req)
if errors.Is(err, fiber.ErrHandlerExited) {
    t.Fatal("handler panicked or called runtime.Goexit; check handler code")
}

Prevention

When it happens

Trigger: Inside app.Test(...), a handler calls runtime.Goexit(), or a panic occurs that is not recovered by Fiber's recovery middleware, causing the deferred channel send at app.go:1442 to fire. Test helpers that spawn goroutines which call runtime.Goexit() also trigger it.

Common situations: Handler code imported from a library that uses runtime.Goexit() on validation failure, a panic that bypasses recovery (e.g. in a goroutine spawned by the handler), or test setup that nils the recovery middleware.

Related errors


AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04). Data as JSON: /data/errors/025e8f33c9fd9f0b.json. Report an issue: GitHub.