gofiber/fiber · error
failed to close interim response body: %w
Error message
failed to close interim response body: %w
What it means
Returned by App.Test (app.go:1505) when res.Body.Close() fails on a 1xx interim response body, immediately after discarding it. Like the discard error, it only occurs while Test walks interim responses; a Close failure indicates the underlying reader/connection rejected cleanup of the interim body.
Source
Thrown at app.go:1505
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() {
// lock application
app.mutex.Lock()
defer app.mutex.Unlock()View on GitHub (pinned to 9a4c7e57fe)
Solutions
- Inspect the wrapped error to identify the close failure cause.
- Ensure the handler writes interim responses without a body and transitions cleanly to the final response.
- Increase TestConfig.Timeout if timing contributes to a torn connection.
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 close interim response body") {
// interim body Close() failed — usually a torn connection
} Prevention
- Avoid handlers that reset the connection between interim and final responses.
- Use a generous TestConfig.Timeout when exercising Early Hints / 100-Continue paths.
- Inspect wrapped close errors to find the underlying reader issue.
When it happens
Trigger: Same interim-response loop as error 73: the handler emits 1xx responses and closing the interim body fails — typically because the connection was already torn down or the body reader is in a bad state.
Common situations: Early-Hints/100-Continue tests with handlers that mismanage response bodies; connection resets between interim and final responses.
Related errors
- failed to discard 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/d0ddfa50fc1de09d.json.
Report an issue: GitHub.