gofiber/fiber · critical
favicon: read limited: %w
Error message
favicon: read limited: %w
What it means
Returned by readLimited (favicon.go:103-108) when io.ReadAll fails while reading the favicon from the configured File or FileSystem. favicon.New PANICS with this error at startup (lines 48-49 and 58-59), so it crashes the process during handler construction rather than at request time.
Source
Thrown at middleware/favicon/favicon.go:107
}
// Serve cached favicon
if iconLen > 0 {
c.Set(fiber.HeaderContentLength, iconLenHeader)
c.Set(fiber.HeaderContentType, hType)
c.Set(fiber.HeaderCacheControl, cfg.CacheControl)
return c.Status(fiber.StatusOK).Send(iconData)
}
return c.SendStatus(fiber.StatusNoContent)
}
}
func readLimited(reader io.Reader, maxBytes int64) ([]byte, error) {
limit := maxBytes + 1
data, err := io.ReadAll(io.LimitReader(reader, limit))
if err != nil {
return nil, fmt.Errorf("favicon: read limited: %w", err)
}
if int64(len(data)) > maxBytes {
return nil, fmt.Errorf("favicon: file size exceeds max bytes %d", maxBytes)
}
return data, nil
}
View on GitHub (pinned to 9a4c7e57fe)
Solutions
- Check read permissions AND readability of the file the process actually opens at startup (not just existence).
- If using a custom FileSystem, debug its Open/Read implementation — readLimited consumes whatever it returns.
- Switch to favicon.Config{Data: bytes} to remove filesystem dependency entirely.
- Run the server under the same UID that owns read access to the file.
Example fix
// before
app.Use(favicon.New(favicon.Config{File: "./assets/favicon.ico"}))
// after — embed the bytes, no filesystem dependency
//go:embed assets/favicon.ico
var faviconBytes []byte
app.Use(favicon.New(favicon.Config{Data: faviconBytes})) Defensive patterns
Strategy: validation
Validate before calling
// pre-flight at startup: ensure the file is readable
f, err := os.Open(cfg.File)
if err != nil { log.Fatal(err) }
buf := make([]byte, 1)
if _, err := f.Read(buf); err != nil && err != io.EOF {
log.Fatal(err)
}
_ = f.Close() Prevention
- Run the server under the UID that owns the favicon file.
- Prefer favicon.Config{Data: bytes} over File to remove filesystem dependency.
- Add a startup healthcheck for the asset path.
When it happens
Trigger: Calling favicon.New(favicon.Config{File: path}) where the file exists (os.Open succeeded) but read returns an I/O error — e.g. disk read fault, NFS hiccup, permission revoked between Open and Read, or a fs.FS reader whose Read returns an error mid-stream.
Common situations: Containerized deployments where the favicon file is bind-mounted and the mount becomes unreadable; read permissions differ from open permissions (rare but possible on some filesystems); truncated file.
Related errors
- favicon: file size exceeds max bytes %d
- unexpected error when trying to remove unix socket file %q:
- cannot chmod %#o for %q: %w
- add: invalid http method %s
- runtime.Goexit() called in handler or server panic
AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04).
Data as JSON: /data/errors/87a1ae22cab8acd5.json.
Report an issue: GitHub.