From 8dff06ca596d2d8a77024b6a603127bf76c694ac Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Tue, 20 Oct 2020 16:03:21 -0500 Subject: [PATCH] Explicitely close files for recvfd client *after* they don't matter. (#548) Previous we were allowing the recvfd files to be closed by their finalizer and the GC. This sometimes led to premature closing of files leading to errors like: https://github.com/networkservicemesh/cmd-forwarder-vppagent/issues/187 'Delete' case. This fixes that by closing the files only after the ctx has is Done. Signed-off-by: Ed Warnicke Signed-off-by: Sergey Ershov --- pkg/networkservice/common/mechanisms/recvfd/client.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/networkservice/common/mechanisms/recvfd/client.go b/pkg/networkservice/common/mechanisms/recvfd/client.go index a1130f478..b296eaf32 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/client.go +++ b/pkg/networkservice/common/mechanisms/recvfd/client.go @@ -30,6 +30,7 @@ import ( "github.com/edwarnicke/grpcfd" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" + "github.com/networkservicemesh/sdk/pkg/networkservice/core/trace" ) type recvFDClient struct { @@ -82,6 +83,14 @@ func (r *recvFDClient) Close(ctx context.Context, conn *networkservice.Connectio inodeURLbyFilename: make(map[string]*url.URL), }) + go func(fileMap *perConnectionFileMap, conn *networkservice.Connection) { + <-ctx.Done() + for _, file := range fileMap.filesByInodeURL { + trace.Log(ctx).Infof("Closing file %q related to closed connection %s", file.Name(), conn.GetId()) + _ = file.Close() + } + }(fileMap, conn) + // Whatever happens, clean up the fileMap defer r.fileMaps.Delete(conn.GetId())