gofiber/fiber · error

ErrSharedStorageNotConfigured

ErrSharedStorageNotConfigured

Error message

fiber: shared storage is not configured

What it means

SharedState coordinates state across Fiber instances via a Storage backend. ErrSharedStorageNotConfigured is returned when SharedState methods are called before a Storage has been wired in (the storage field is nil).

Source

Thrown at shared_state.go:17

package fiber

import (
	"context"
	"encoding/hex"
	"encoding/json"
	"encoding/xml"
	"errors"
	"fmt"
	"time"

	"github.com/gofiber/utils/v2"
)

const defaultSharedStatePrefix = "gofiber-shared-state-"

var ErrSharedStorageNotConfigured = errors.New("fiber: shared storage is not configured")

type SharedState struct {
	storage        Storage
	jsonEncoder    utils.JSONMarshal
	jsonDecoder    utils.JSONUnmarshal
	msgPackEncoder utils.MsgPackMarshal
	msgPackDecoder utils.MsgPackUnmarshal
	cborEncoder    utils.CBORMarshal
	cborDecoder    utils.CBORUnmarshal
	xmlEncoder     utils.XMLMarshal
	xmlDecoder     utils.XMLUnmarshal
	prefix         string
}

func newSharedState(cfg *Config) *SharedState {
	if cfg == nil {
		cfg = &Config{}
	}

View on GitHub (pinned to a105acad6c)

Solutions

  1. Configure a Storage backend when creating the app (e.g., Redis for production, memory for single-instance dev).
  2. Assert SharedState is non-nil and has storage before the first call.
  3. Wire Storage explicitly via the app config rather than relying on defaults.

Example fix

// before
app := fiber.New()
app.SharedState().Set("k", "v") // ErrSharedStorageNotConfigured

// after
store := memory.New()
app := fiber.New(fiber.Config{SharedState: &SharedState{Storage: store}})
app.SharedState().Set("k", "v")
Defensive patterns

Strategy: validation

Validate before calling

if app.SharedState() == nil || !hasStorage(app) {
    return fiber.NewError(fiber.StatusServiceUnavailable, "shared state unavailable")
}

Type guard

func hasStorage(app *fiber.App) bool {
    // wire Storage in fiber.Config at construction; assert before first call
    return app != nil && /* Storage field set */ true
}

Prevention

When it happens

Trigger: Calling app.SharedState().Get/Set (or any SharedState method) when the app was created without configuring Config.AppName / a Storage backend, or before passing a Storage to SharedState.

Common situations: Forgetting to wire Storage in production; using SharedState in unit tests without setup; multi-instance deployment expecting shared state while still using the in-process default.

Related errors


AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11). Data as JSON: /api/errors/e8ada147b7439a8a. Report an issue: GitHub.