gofiber/fiber · error

boundary generation

Error message

boundary generation: %w

What it means

When the request body type is filesBody and the boundary is still the default, the client appends a 16-character random suffix to make it unique. This error wraps the unsafeRandString failure that produces that suffix — i.e. a rand.Read failure (see errors 85/86).

Solutions

  1. Restore access to the OS random source (mount /dev/urandom, allow getrandom).
  2. If you supply your own RFC-compliant boundary (req.SetBoundary), the random-suffix step is skipped and this code path is avoided — but the underlying rand failure indicates a deeper host problem.
  3. Treat as a host-level incident, not a request-level retry.

Example fix

// avoid the random-suffix step by supplying your own boundary
req.SetBoundary("----GoFiberBoundaryABC123")
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Uploading files via the client when the OS random source is unavailable; the boundary could not be randomized, so the multipart writer cannot be safely configured for this request.

Common situations: Restricted sandboxes/containers without /dev/urandom; getrandom denied by seccomp; embedded early-boot scenarios.

Related errors


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

Appendix: source

Thrown at client/hooks.go:153

	// Set Content-Type and Accept headers based on the request body type.
	switch req.bodyType {
	case jsonBody:
		req.RawRequest.Header.SetContentType(applicationJSON)
		req.RawRequest.Header.Set(headerAccept, applicationJSON)
	case xmlBody:
		req.RawRequest.Header.SetContentType(applicationXML)
	case cborBody:
		req.RawRequest.Header.SetContentType(applicationCBOR)
	case formBody:
		req.RawRequest.Header.SetContentType(applicationForm)
	case filesBody:
		req.RawRequest.Header.SetContentType(multipartFormData)
		// If boundary is default, append a random string to it.
		if req.boundary == boundary {
			randStr, err := unsafeRandString(16)
			if err != nil {
				return fmt.Errorf("boundary generation: %w", err)
			}
			req.boundary += randStr
		}
		req.RawRequest.Header.SetMultipartFormBoundary(req.boundary)
	default:
		// noBody or rawBody do not require special handling here.
	}

	// Set User-Agent header.
	req.RawRequest.Header.SetUserAgent(defaultUserAgent)
	if c.userAgent != "" {
		req.RawRequest.Header.SetUserAgent(c.userAgent)
	}
	if req.userAgent != "" {
		req.RawRequest.Header.SetUserAgent(req.userAgent)
	}

	// Set Referer header.

View on GitHub (pinned to a105acad6c)