From 1c6af042015c247662f46ccc2c7028d04e29fd99 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik <93182827+NikitaSkrynnik@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:56:55 +0700 Subject: [PATCH] fix context leak in timeout chain element (#1681) Signed-off-by: NikitaSkrynnik --- pkg/networkservice/common/timeout/server.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/networkservice/common/timeout/server.go b/pkg/networkservice/common/timeout/server.go index 277028fea..9725d4e34 100644 --- a/pkg/networkservice/common/timeout/server.go +++ b/pkg/networkservice/common/timeout/server.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2020-2023 Cisco Systems, Inc. +// Copyright (c) 2020-2024 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -77,10 +77,11 @@ func (s *timeoutServer) Request(ctx context.Context, request *networkservice.Net afterCh := timeClock.After(timeClock.Until(expirationTime) - requestTimeout) go func(cancelCtx context.Context, afterCh <-chan time.Time) { + defer cancel() select { case <-cancelCtx.Done(): case <-afterCh: - eventFactory.Close(begin.CancelContext(cancelCtx)) + <-eventFactory.Close(begin.CancelContext(cancelCtx)) } }(cancelCtx, afterCh)