{"id":"d0ddfa50fc1de09d","repo":"gofiber/fiber","slug":"failed-to-close-interim-response-body-w","errorCode":null,"errorMessage":"failed to close interim response body: %w","messagePattern":"failed to close interim response body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app.go","lineNumber":1505,"sourceCode":"\t\tif err != nil {\n\t\t\tif errors.Is(err, io.ErrUnexpectedEOF) {\n\t\t\t\treturn nil, ErrTestGotEmptyResponse\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"failed to read response: %w\", err)\n\t\t}\n\n\t\t// Break if this response is non-1xx or there are no more responses\n\t\tif res.StatusCode >= http.StatusOK || buffer.Buffered() == 0 {\n\t\t\tbreak\n\t\t}\n\n\t\t// Discard interim response body before reading the next one\n\t\tif res.Body != nil {\n\t\t\tif _, errCopy := io.Copy(io.Discard, res.Body); errCopy != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to discard interim response body: %w\", errCopy)\n\t\t\t}\n\t\t\tif errClose := res.Body.Close(); errClose != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to close interim response body: %w\", errClose)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn res, nil\n}\n\ntype disableLogger struct{}\n\n// Printf implements the fasthttp Logger interface and discards log output.\nfunc (*disableLogger) Printf(string, ...any) {\n}\n\nfunc (app *App) init() *App {\n\tfunc() {\n\t\t// lock application\n\t\tapp.mutex.Lock()\n\t\tdefer app.mutex.Unlock()","sourceCodeStart":1487,"sourceCodeEnd":1523,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/app.go#L1487-L1523","documentation":"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.","triggerScenarios":"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.","commonSituations":"Early-Hints/100-Continue tests with handlers that mismanage response bodies; connection resets between interim and final responses.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"resp, err := app.Test(req, fiber.TestConfig{Timeout: 5 * time.Second})\nif err != nil && strings.Contains(err.Error(), \"failed to close interim response body\") {\n    // interim body Close() failed — usually a torn connection\n}","preventionTips":["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."],"tags":["testing","http","interim-response","test-helper"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}