-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed recvfd leaks #1173
Fixed recvfd leaks #1173
Changes from 3 commits
c7b4986
5d58f01
1895c74
9f4f9ab
6f613aa
a21604d
51703c4
0c19391
55d55c8
a178bfe
007843e
b2faeee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ | |||||||
// See the License for the specific language governing permissions and | ||||||||
// limitations under the License. | ||||||||
|
||||||||
//+build !windows | ||||||||
// +build !windows | ||||||||
|
||||||||
package nsmgr_test | ||||||||
|
||||||||
|
@@ -38,6 +38,10 @@ import ( | |||||||
"github.com/networkservicemesh/sdk/pkg/tools/sandbox" | ||||||||
) | ||||||||
|
||||||||
const ( | ||||||||
linuxOsName = "linux" | ||||||||
) | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change was required by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just don't check on OS name. See at first comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. Thanks, Denis! |
||||||||
func Test_Local_NoURLUsecase(t *testing.T) { | ||||||||
t.Cleanup(func() { goleak.VerifyNone(t) }) | ||||||||
|
||||||||
|
@@ -84,7 +88,7 @@ func Test_Local_NoURLUsecase(t *testing.T) { | |||||||
} | ||||||||
|
||||||||
func Test_MultiForwarderSendfd(t *testing.T) { | ||||||||
if runtime.GOOS != "linux" { | ||||||||
if runtime.GOOS != linuxOsName { | ||||||||
t.Skip("sendfd works only on linux") | ||||||||
} | ||||||||
t.Cleanup(func() { goleak.VerifyNone(t) }) | ||||||||
|
@@ -160,3 +164,49 @@ func Test_MultiForwarderSendfd(t *testing.T) { | |||||||
require.NoError(t, err) | ||||||||
require.Equal(t, 1, counter.Closes()) | ||||||||
} | ||||||||
|
||||||||
func Test_TimeoutRecvfd(t *testing.T) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain how this test checks the problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Client makes a request with an expired token thus triggering timeout ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test is incorrect.
Please add test for recvfd package. Also, I think we do not need to use sandbox here. Because we simply need to check cleaning and sandbox is overkilled thing for it. |
||||||||
if runtime.GOOS != linuxOsName { | ||||||||
t.Skip("recvfd works only on linux") | ||||||||
} | ||||||||
t.Cleanup(func() { goleak.VerifyNone(t) }) | ||||||||
|
||||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||||||||
defer cancel() | ||||||||
|
||||||||
domain := sandbox.NewBuilder(ctx, t). | ||||||||
UseUnixSockets(). | ||||||||
SetNodeSetup(func(ctx context.Context, node *sandbox.Node, _ int) { | ||||||||
node.NewNSMgr(ctx, "nsmgr", nil, sandbox.GenerateTestToken, nsmgr.NewServer) | ||||||||
node.NewForwarder(ctx, ®istry.NetworkServiceEndpoint{ | ||||||||
Name: "forwarder-1", | ||||||||
NetworkServiceNames: []string{"forwarder"}, | ||||||||
NetworkServiceLabels: map[string]*registry.NetworkServiceLabels{ | ||||||||
"forwarder": { | ||||||||
Labels: map[string]string{ | ||||||||
"p2p": "true", | ||||||||
}, | ||||||||
}, | ||||||||
}, | ||||||||
}, sandbox.GenerateTestToken, recvfd.NewServer()) | ||||||||
}). | ||||||||
Build() | ||||||||
|
||||||||
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken) | ||||||||
|
||||||||
nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService()) | ||||||||
require.NoError(t, err) | ||||||||
|
||||||||
nseReg := defaultRegistryEndpoint(nsReg.Name) | ||||||||
|
||||||||
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken) | ||||||||
|
||||||||
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateExpiringToken(0), kernel.NewClient(), sendfd.NewClient()) | ||||||||
|
||||||||
request := defaultRequest(nsReg.Name) | ||||||||
|
||||||||
conn, err := nsc.Request(ctx, request.Clone()) | ||||||||
require.Nil(t, err) | ||||||||
require.NotNil(t, conn) | ||||||||
require.Equal(t, 4, len(conn.Path.PathSegments)) | ||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -78,18 +78,21 @@ func (r *recvFDServer) Request(ctx context.Context, request *networkservice.Netw | |||||
} | ||||||
|
||||||
func (r *recvFDServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { | ||||||
// Clean up the fileMap no matter what happens | ||||||
defer r.fileMaps.Delete(conn.GetId()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// Get the grpcfd.FDRecver | ||||||
recv, ok := grpcfd.FromContext(ctx) | ||||||
if !ok { | ||||||
r.closeFiles(conn) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return next.Server(ctx).Close(ctx, conn) | ||||||
} | ||||||
|
||||||
// Get the fileMap | ||||||
fileMap, _ := r.fileMaps.LoadOrStore(conn.GetId(), &perConnectionFileMap{ | ||||||
filesByInodeURL: make(map[string]*os.File), | ||||||
inodeURLbyFilename: make(map[string]*url.URL), | ||||||
}) | ||||||
// Clean up the fileMap no matter what happens | ||||||
defer r.fileMaps.Delete(conn.GetId()) | ||||||
|
||||||
// Recv the FD and Swap the Inode for a file in InodeURL in Parameters | ||||||
err := recvFDAndSwapInodeToFile(ctx, fileMap, conn.GetMechanism().GetParameters(), recv) | ||||||
|
@@ -107,3 +110,15 @@ func (r *recvFDServer) Close(ctx context.Context, conn *networkservice.Connectio | |||||
err = swapFileToInode(fileMap, conn.GetMechanism().GetParameters(), true) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return &empty.Empty{}, err | ||||||
} | ||||||
|
||||||
func (r *recvFDServer) closeFiles(conn *networkservice.Connection) { | ||||||
denis-tingaikin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
fileMap, _ := r.fileMaps.LoadOrStore(conn.GetId(), &perConnectionFileMap{ | ||||||
filesByInodeURL: make(map[string]*os.File), | ||||||
inodeURLbyFilename: make(map[string]*url.URL), | ||||||
}) | ||||||
|
||||||
for inodeURLStr, file := range fileMap.filesByInodeURL { | ||||||
delete(fileMap.filesByInodeURL, inodeURLStr) | ||||||
_ = file.Close() | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.