From ad14f31189c48cb3ef79e78625143b640fa4fb4e Mon Sep 17 00:00:00 2001 From: Milkshak3s Date: Thu, 14 Apr 2022 14:41:27 -0400 Subject: [PATCH] Close GCS writer on return Signed-off-by: Milkshak3s --- outputs/gcp.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/outputs/gcp.go b/outputs/gcp.go index 4d7cd6b29..b9cf28c81 100644 --- a/outputs/gcp.go +++ b/outputs/gcp.go @@ -171,7 +171,9 @@ func (c *Client) UploadGCS(falcopayload types.FalcoPayload) { } key := fmt.Sprintf("%s/%s/%s.json", prefix, t.Format("2006-01-02"), t.Format(time.RFC3339Nano)) - _, err := c.GCSStorageClient.Bucket(c.Config.GCP.Storage.Bucket).Object(key).NewWriter(context.Background()).Write(payload) + bucketWriter := c.GCSStorageClient.Bucket(c.Config.GCP.Storage.Bucket).Object(key).NewWriter(context.Background()) + defer bucketWriter.Close() + _, err := bucketWriter.Write(payload) if err != nil { log.Printf("[ERROR] : GCPStorage - %v - %v\n", "Error while Uploading message", err.Error()) c.Stats.GCPStorage.Add(Error, 1)