From 58ddbfa4ac4a21df2966767687b61939523a005c Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 9 Sep 2024 16:46:47 -0400 Subject: [PATCH] Fixes issue where context cancelling could result in an invalid error being reported (#5329) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix issue. * Update internal/pkg/agent/application/gateway/fleet/fleet_gateway.go Co-authored-by: Paolo ChilĂ  * Remove check for failed as it no-longer gets marked failed. --------- Co-authored-by: Paolo ChilĂ  Co-authored-by: Pierre HILBERT Co-authored-by: Julien Lind Co-authored-by: Shaunak Kashyap (cherry picked from commit 96e02e0a8640d6019c10f41b35a2c4ec53416377) --- .../pkg/agent/application/gateway/fleet/fleet_gateway.go | 8 +++++++- testing/integration/endpoint_security_test.go | 5 ----- testing/integration/linux_rpm_test.go | 2 -- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/pkg/agent/application/gateway/fleet/fleet_gateway.go b/internal/pkg/agent/application/gateway/fleet/fleet_gateway.go index e028205fd3a..7bfc5d90bba 100644 --- a/internal/pkg/agent/application/gateway/fleet/fleet_gateway.go +++ b/internal/pkg/agent/application/gateway/fleet/fleet_gateway.go @@ -198,7 +198,13 @@ func (f *FleetGateway) doExecute(ctx context.Context, bo backoff.Backoff) (*flee } if !bo.Wait() { - // Something bad has happened and we log it and we should update our current state. + if ctx.Err() != nil { + // if the context is cancelled, break out of the loop + break + } + + // This should not really happen, but just in-case this error is used to show that + // something strange occurred and we want to log it and report it. err := errors.New( "checkin retry loop was stopped", errors.TypeNetwork, diff --git a/testing/integration/endpoint_security_test.go b/testing/integration/endpoint_security_test.go index bcda661ca95..6a713a42730 100644 --- a/testing/integration/endpoint_security_test.go +++ b/testing/integration/endpoint_security_test.go @@ -275,11 +275,6 @@ func testInstallAndUnenrollWithEndpointSecurity(t *testing.T, info *define.Info, return false } - if state.FleetState != client.Failed { - t.Logf("Fleet state has not been marked as failed yet!\n%+v", state) - return false - } - return true }, endpointHealthPollingTimeout, diff --git a/testing/integration/linux_rpm_test.go b/testing/integration/linux_rpm_test.go index 0f49e306996..4f5c6fc38aa 100644 --- a/testing/integration/linux_rpm_test.go +++ b/testing/integration/linux_rpm_test.go @@ -44,8 +44,6 @@ func TestRpmLogIngestFleetManaged(t *testing.T) { Sudo: true, }) - t.Skip("Flaky https://github.com/elastic/elastic-agent/issues/5311") - ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute)) defer cancel()