{"id":"1fba0994cb9f1f60","repo":"gofiber/fiber","slug":"limiter-unexpected-entry-type-t-for-key-q","errorCode":null,"errorMessage":"limiter: unexpected entry type %T for key %q","messagePattern":"limiter: unexpected entry type %T for key %q","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/limiter/manager.go","lineNumber":90,"sourceCode":"\t\tif raw != nil {\n\t\t\tit := m.acquire()\n\t\t\tif _, err := it.UnmarshalMsg(raw); err != nil {\n\t\t\t\tm.release(it)\n\t\t\t\treturn nil, fmt.Errorf(\"limiter: failed to unmarshal key %q: %w\", m.logKey(key), err)\n\t\t\t}\n\t\t\treturn it, nil\n\t\t}\n\t\treturn m.acquire(), nil\n\t}\n\n\tvalue := m.memory.Get(key)\n\tif value == nil {\n\t\treturn m.acquire(), nil\n\t}\n\n\tit, ok := value.(*item)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"limiter: unexpected entry type %T for key %q\", value, m.logKey(key))\n\t}\n\n\treturn it, nil\n}\n\n// set data to storage or memory\nfunc (m *manager) set(ctx context.Context, key string, it *item, exp time.Duration) error {\n\tif m.storage != nil {\n\t\traw, err := it.MarshalMsg(nil)\n\t\tif err != nil {\n\t\t\tm.release(it)\n\t\t\treturn fmt.Errorf(\"limiter: failed to marshal key %q: %w\", m.logKey(key), err)\n\t\t}\n\t\tif err := m.storage.SetWithContext(ctx, key, raw, exp); err != nil {\n\t\t\tm.release(it)\n\t\t\treturn fmt.Errorf(\"limiter: failed to store key %q: %w\", m.logKey(key), err)\n\t\t}\n\t\tm.release(it)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/limiter/manager.go#L72-L108","documentation":"Returned by the in-memory path of manager.get when the value stored under the key in the in-memory store is not an *item. The code does it, ok := value.(*item); this type assertion fails when memory.Get yields something that is not the expected limiter item type.","triggerScenarios":"Limiter is running with the default in-memory storage (no fiber.Storage configured) and memory.Get returns a non-nil value whose dynamic type is not *item. In normal operation only *item values are stored, so this indicates the memory.Storage is being shared/misused across components that write a different type under the same key.","commonSituations":"Two middleware instances or another package sharing the same memory.Storage and writing a different value type to the same key; a fork or custom patch that stores a different struct; race/corruption in a shared in-memory store.","solutions":["Ensure each limiter instance uses its own memory.Storage rather than sharing one across middlewares/packages.","Check that no custom code writes into the limiter's memory store.","If sharing storage is intentional, isolate by key namespace so types never collide."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure each limiter uses a private in-memory store; do not share\n// memory.Storage across middlewares.\nfunc newIsolatedLimiter() fiber.Handler {\n    // Omit Storage in Config to get a fresh internal memory store per call\n    // to limiter.New.\n    return limiter.New()\n}","typeGuard":null,"tryCatchPattern":"// Treat an internal type-assertion failure as a 500 and log it loudly,\n// since it signals store misuse rather than a client error.\nif strings.Contains(err.Error(), \"unexpected entry type\") {\n    log.Error().Err(err).Msg(\"limiter memory store type collision\")\n    return c.Status(500).SendString(\"internal error\")\n}","preventionTips":["Never reuse one memory.Storage across limiter instances or packages.","Keep the limiter's key namespace exclusive to the limiter.","Audit custom forks that store into the limiter's memory store."],"tags":["limiter","memory","type-assertion","invariant"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}