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

  1. Check read permissions AND readability of the file the process actually opens at startup (not just existence).
  2. If using a custom FileSystem, debug its Open/Read implementation — readLimited consumes whatever it returns.
  3. Switch to favicon.Config{Data: bytes} to remove filesystem dependency entirely.
  4. 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

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


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