Skip to content

Commit

Permalink
Explicitely close files for recvfd client *after* they don't matter.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
edwarnicke committed Oct 20, 2020
1 parent 58a2907 commit 587f0a1
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 587f0a1

Please sign in to comment.