From 773d377a5ae2d9ea76a40eefde4a899775ab3ab1 Mon Sep 17 00:00:00 2001 From: Alyx Holms Date: Fri, 20 Oct 2023 11:49:23 -0600 Subject: [PATCH] draft: add close to body to prevent deadlock --- cmd/start.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/start.go b/cmd/start.go index 8fc2e38..9c7ef62 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -224,6 +224,9 @@ func ingest(ctx context.Context, bheUrl url.URL, bheClient *http.Client, in <-ch log.Error(ErrExceededRetryLimit, "") hasErrors = true } + if err := response.Body.Close(); err != nil { + log.Error(fmt.Errorf("failed to close ingest body: %w", err), unrecoverableErrMsg) + } continue } else if response.StatusCode != http.StatusAccepted { if bodyBytes, err := io.ReadAll(response.Body); err != nil { @@ -231,7 +234,14 @@ func ingest(ctx context.Context, bheUrl url.URL, bheClient *http.Client, in <-ch } else { log.Error(fmt.Errorf("received unexpected response code from %v: %s %s", req.URL, response.Status, bodyBytes), unrecoverableErrMsg) } + if err := response.Body.Close(); err != nil { + log.Error(fmt.Errorf("failed to close ingest body: %w", err), unrecoverableErrMsg) + } return true + } else { + if err := response.Body.Close(); err != nil { + log.Error(fmt.Errorf("failed to close ingest body: %w", err), unrecoverableErrMsg) + } } } }