Skip to content

Commit

Permalink
Explicitely close files for recvfd client *after* they don't matter. (n…
Browse files Browse the repository at this point in the history
…etworkservicemesh#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:

networkservicemesh/cmd-forwarder-vppagent#187

'Delete' case.  This fixes that by closing the files only after the
ctx has is Done.

Signed-off-by: Ed Warnicke <hagbard@gmail.com>
Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
  • Loading branch information
edwarnicke authored and Sergey Ershov committed Dec 20, 2020
1 parent b6c9cbb commit 8dff06c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/networkservice/common/mechanisms/recvfd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())

Expand Down

0 comments on commit 8dff06c

Please sign in to comment.