From e6781f3d1c5aa9292cad1cadd8d28001522a18f2 Mon Sep 17 00:00:00 2001 From: Andrew Gizas Date: Thu, 6 Mar 2025 19:24:27 +0200 Subject: [PATCH] [AWSs3 Input] Handle unexpectedEOF errors (#42420) * return EOF error again as errS3DownloadFailed Signed-off-by: Andreas Gkizas --------- Signed-off-by: Andreas Gkizas Co-authored-by: Kavindu Dodanduwa --- CHANGELOG.next.asciidoc | 1 + x-pack/filebeat/input/awss3/s3_objects.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 79dda48534a1..451b2ff6f4bc 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -215,6 +215,7 @@ otherwise no tag is added. {issue}42208[42208] {pull}42403[42403] - Fix entityanalytics activedirectory provider full sync use before initialization bug. {pull}42682[42682] - In the `http_endpoint` input, fix the check for a missing HMAC HTTP header. {pull}42756[42756] - Prevent computer details being returned for user queries by Activedirectory Entity Analytics provider. {issue}11818[11818] {pull}42796[42796] +- Handle unexpectedEOF error in aws-s3 input and enforce retrying using download failed error {pull}42420[42756] *Heartbeat* diff --git a/x-pack/filebeat/input/awss3/s3_objects.go b/x-pack/filebeat/input/awss3/s3_objects.go index 93cb0f262bdc..0cdd8094634a 100644 --- a/x-pack/filebeat/input/awss3/s3_objects.go +++ b/x-pack/filebeat/input/awss3/s3_objects.go @@ -266,7 +266,12 @@ func (p *s3ObjectProcessor) addGzipDecoderIfNeeded(body io.Reader) (io.Reader, e } func (p *s3ObjectProcessor) readJSON(r io.Reader) error { - dec := json.NewDecoder(r) + var buf bytes.Buffer + if _, err := io.Copy(&buf, r); err != nil { + // If an error occurs during the download, handle it here + return fmt.Errorf("%w: %w", errS3DownloadFailed, err) + } + dec := json.NewDecoder(&buf) dec.UseNumber() for dec.More() && p.ctx.Err() == nil {