goharbor/harbor · error

failed to read request body

Error message

failed to read request body

What it means

Request-body read failure in the audit-log middleware: after PreCheckMetadata matched the request as auditable, io.ReadAll on the request body returned an error (e.g. client aborted mid-upload, connection reset, or an oversized/invalid body). The middleware cannot capture the request content for the audit event, so it aborts with a 500 instead of logging an incomplete audit record.

Solutions

  1. Retry the request — transient network interruptions during body upload are a common cause
  2. Check for proxy/body-size limits between client and Harbor that could truncate the upload
  3. If persistent, capture the underlying read error (server-side) and inspect client connectivity to core
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at src/server/middleware/log/log.go:58 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/822aba42310786e1. Report an issue: GitHub.

Appendix: source

Thrown at src/server/middleware/log/log.go:58

		}

		traceID := tracelib.ExractTraceID(r)
		if traceID != "" {
			ctx := log.WithLogger(r.Context(), log.G(r.Context()).WithFields(log.Fields{"traceID": traceID}))
			r = r.WithContext(ctx)
		}

		e := &commonevent.Metadata{
			Ctx:           r.Context(),
			Username:      "unknown",
			RequestMethod: r.Method,
			RequestURL:    r.URL.String(),
		}
		if matched, resName := e.PreCheckMetadata(); matched {
			lib.NopCloseRequest(r)
			body, err := io.ReadAll(r.Body)
			if err != nil {
				http.Error(w, "failed to read request body", http.StatusInternalServerError)
				return
			}
			requestContent := string(body)
			if secCtx, ok := security.FromContext(r.Context()); ok {
				e.Username = secCtx.GetUsername()
			}
			rw := &ResponseWriter{
				ResponseWriter: w,
				statusCode:     http.StatusOK,
			}
			next.ServeHTTP(rw, r)

			// Add information in the response
			e.ResourceName = resName
			e.RequestPayload = requestContent
			e.ResponseCode = rw.statusCode

			// Need to parse the Location header to get the resource ID on creating resource

View on GitHub (pinned to 7b2fd08cc5)