gofiber/fiber · error
failed to discard interim response body: %w
Error message
failed to discard interim response body: %w
What it means
Returned by App.Test (app.go:1502) when discarding the body of a 1xx interim response fails before reading the next response in the loop. Test loops over interim responses (100 Continue, 102 Processing, 103 Early Hints) and discards each body; if io.Copy(io.Discard, res.Body) errors, the interim body could not be drained.
Source
Thrown at app.go:1502
for {
// Convert raw http response to *http.Response
res, err = httpReadResponse(buffer, req)
if err != nil {
if errors.Is(err, io.ErrUnexpectedEOF) {
return nil, ErrTestGotEmptyResponse
}
return nil, fmt.Errorf("failed to read response: %w", err)
}
// Break if this response is non-1xx or there are no more responses
if res.StatusCode >= http.StatusOK || buffer.Buffered() == 0 {
break
}
// Discard interim response body before reading the next one
if res.Body != nil {
if _, errCopy := io.Copy(io.Discard, res.Body); errCopy != nil {
return nil, fmt.Errorf("failed to discard interim response body: %w", errCopy)
}
if errClose := res.Body.Close(); errClose != nil {
return nil, fmt.Errorf("failed to close interim response body: %w", errClose)
}
}
}
return res, nil
}
type disableLogger struct{}
// Printf implements the fasthttp Logger interface and discards log output.
func (*disableLogger) Printf(string, ...any) {
}
func (app *App) init() *App {
func() {View on GitHub (pinned to 9a4c7e57fe)
Solutions
- Inspect the wrapped error (usually io.ErrUnexpectedEOF or a read on a closed conn).
- Ensure interim responses in the handler carry no body (or a validly framed one) per RFC 2516.
- Increase TestConfig.Timeout if the handler is slow to produce the final response after interim ones.
Defensive patterns
Strategy: try-catch
Try / catch
resp, err := app.Test(req, fiber.TestConfig{Timeout: 5 * time.Second})
if err != nil && strings.Contains(err.Error(), "failed to discard interim response body") {
// 1xx interim response body could not be drained — inspect handler's interim writes
} Prevention
- Ensure interim (1xx) responses carry no body per RFC.
- Increase TestConfig.Timeout if the handler is slow to produce the final response.
- Inspect wrapped errors to distinguish read failures from connection resets.
When it happens
Trigger: A handler under test emits 1xx interim responses with a body that errors on read (broken/short body), or the testConn is closed mid-interim-response. Occurs specifically when exercising interim-response code paths.
Common situations: Testing Early Hints (103) / 100-Continue flows; handlers that write interim status then reset the connection; compression/streaming edge cases on interim responses.
Related errors
- failed to close interim response body: %w
- failed to dump request: %w
- failed to write: %w
- failed to read response: %w
- runtime.Goexit() called in handler or server panic
AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04).
Data as JSON: /data/errors/3b12e5745bb2978a.json.
Report an issue: GitHub.