From f92374eb43c45b04370d01f573effd5675b3a222 Mon Sep 17 00:00:00 2001 From: NikitaSkrynnik Date: Mon, 14 Oct 2024 21:35:55 +0700 Subject: [PATCH] fix context leak in timeout chain element 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)