{"record":{"id":"daa17418ee48e5a3","repo":"chenhg5/cc-connect","slug":"googlechat-close-update-response-body-w","errorCode":null,"errorMessage":"googlechat: close update response body: %w","messagePattern":"googlechat: close update response body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"platform/googlechat/streaming.go","lineNumber":101,"sourceCode":"\turl, body, err := buildUpdateRequest(h.name, content)\n\tif err != nil {\n\t\treturn err\n\t}\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPatch, url, bytes.NewReader(body))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"googlechat: build update request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\tresp, err := p.doRequest(req)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif _, err := io.Copy(io.Discard, resp.Body); err != nil {\n\t\t_ = resp.Body.Close()\n\t\treturn fmt.Errorf(\"googlechat: drain update response body: %w\", err)\n\t}\n\tif err := resp.Body.Close(); err != nil {\n\t\treturn fmt.Errorf(\"googlechat: close update response body: %w\", err)\n\t}\n\treturn nil\n}\n\nvar (\n\t_ core.MessageUpdater = (*Platform)(nil)\n\t_ core.PreviewStarter = (*Platform)(nil)\n)\n","sourceCodeStart":83,"sourceCodeEnd":110,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/googlechat/streaming.go#L83-L110","documentation":"This error is returned by Platform.UpdateMessage when resp.Body.Close() fails after a successful update request and drain. Body close failures on HTTP responses are rare and typically indicate the connection was already torn down or a reset occurred while closing. The update itself almost certainly succeeded, since the body was fully read first.","triggerScenarios":"Calling UpdateMessage when the HTTP client's response body Close encounters a broken connection (e.g. keep-alive connection reset at close time).","commonSituations":"Idle keep-alive connections expiring between Google's servers and the client; aggressive connection reaping by NATs, load balancers, or firewalls.","solutions":["Treat as non-fatal: the message update already succeeded, so log the error instead of failing the operation.","Disable or shorten HTTP keep-alive if stale connections repeatedly cause this.","Retry only if the caller requires the update call to return nil.","Check for middleware/wrappers around http.RoundTripper that mishandle body closure."],"exampleFix":"// before\nif err := resp.Body.Close(); err != nil {\n    return fmt.Errorf(\"googlechat: close update response body: %w\", err)\n}\n// after\nif cerr := resp.Body.Close(); cerr != nil {\n    // update succeeded; close failure is not fatal\n    slog.Warn(\"googlechat: close update response body\", \"err\", cerr)\n}\nreturn nil","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go: treat close errors as non-fatal\nif err := platform.UpdateMessage(ctx, msgID, content); err != nil {\n    if strings.Contains(err.Error(), \"close update response body\") {\n        slog.Warn(\"non-fatal body close error after update\", \"err\", err)\n    } else {\n        return err\n    }\n}","preventionTips":["Log-and-continue for close-after-drain errors; the write already succeeded.","Refresh keep-alive connections periodically to avoid stale-connection close errors.","Keep http.Transport settings (MaxIdleConns, IdleConnTimeout) sane for long-running daemons."],"tags":["googlechat","http","resource-cleanup"],"backgroundTag":"http-error-response","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}