Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

vc: fix netns leak#1641

Merged
lifupan merged 1 commit intokata-containers:masterfrom
Ace-Tang:leak-ns
May 10, 2019
Merged

vc: fix netns leak#1641
lifupan merged 1 commit intokata-containers:masterfrom
Ace-Tang:leak-ns

Conversation

@Ace-Tang
Copy link
Contributor

@Ace-Tang Ace-Tang commented May 8, 2019

when kata container start fails, netns will leak, add a defer func
to fix it

Fixes: #1640

Signed-off-by: Ace-Tang aceapril@126.com

ns := sandboxConfig.NetworkConfig
if err != nil && ns.NetNsCreated {
if ex := cleanupNetNS(ns.NetNSPath); ex != nil {
kataUtilsLogger.Warnf("Failed to cleanup netns %s", ns.NetNSPath)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use WithField in all the logs to avoid using format specifiers. for example

kataUtilsLogger.WithField("path", ns.NetNSPath).Warn("Failed to cleanup netns")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Member

@amshinde amshinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor suggestion. lgtm otherwise. Thanks for fixing this @Ace-Tang


err = n.Close()
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you return a more verbose message here : "Failed to close netns: %s"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@lifupan
Copy link
Member

lifupan commented May 9, 2019

/test

Copy link
Contributor

@grahamwhaley grahamwhaley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

ns := sandboxConfig.NetworkConfig
if err != nil && ns.NetNsCreated {
if ex := cleanupNetNS(ns.NetNSPath); ex != nil {
kataUtilsLogger.WithField("path", ns.NetNSPath).Warn("Failed to cleanup netns")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tweak this slightly to also include the error:

kataUtilsLogger.WithField("path", ns.NetNSPath).WithError(ex).Warn("Failed to cleanup netns")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes , forget to log error

@grahamwhaley
Copy link
Contributor

I've nudged a few CI rebuilds.
The metrics one just looked like something fell over.
The fedora and vsocks ones (which is also fedora) both had what looked like the same fail - I suspect it is not related to this PR, so respan. Here is the error for ref, in case it does re-occur:

• Failure [22.752 seconds]
state
/tmp/jenkins/workspace/kata-containers-runtime-fedora-PR/go/src/github.com/kata-containers/tests/functional/state_test.go:26
  container
  /tmp/jenkins/workspace/kata-containers-runtime-fedora-PR/go/src/github.com/kata-containers/tests/vendor/github.com/onsi/ginkgo/extensions/table/table.go:92
    with workload [true], timeWait 5 [It]
    /tmp/jenkins/workspace/kata-containers-runtime-fedora-PR/go/src/github.com/kata-containers/tests/vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go:46

    Expected
        <int>: 1
    to equal
        <int>: 0

    /tmp/jenkins/workspace/kata-containers-runtime-fedora-PR/go/src/github.com/kata-containers/tests/functional/state_test.go:45
------------------------------
SS

Summarizing 1 Failure:

[Fail] state container [It] with workload [true], timeWait 5 

Copy link

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ace-Tang.

lgtm

ns := sandboxConfig.NetworkConfig
if err != nil && ns.NetNsCreated {
if ex := cleanupNetNS(ns.NetNSPath); ex != nil {
kataUtilsLogger.WithField("path", ns.NetNSPath).WithError(ex).Warn("Failed to cleanup netns")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might find that the CI linters complain as errors should start with a lower-case letter (same comment for errors below...)

Copy link
Contributor Author

@Ace-Tang Ace-Tang May 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was vary confuse about this, if my memory is right, golang advised log should be begin with lower-case. But kata use them both, that confused me, so I followed the upper-case way.
Make all log begin with lower-case?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Ace-Tang - sorry! I meant to put this comment on the first of your new fmt.Errorf() calls as this clearly isn't an error, but a log call that's logging an error ;)

But yes, I think you are correct - we need to be more consistent and make all errors start with a lower-case letter at some point (not this PR).

But, for now, if the CI is happy, I'm happy 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @jodh-intel ,do you mean

n, err := ns.GetNS(netNSPath)
187     if err != nil { 
188         return fmt.Errorf("Failed to get netns %s: %v", netNSPath, err)   --> change Fail to fail, is it ?
189     }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. As I say, if the CI checks are happy, no need to change strictly. But I think this should probably be:

return fmt.Errorf("failed to get netns %s: %v", netNSPath, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update, @jodh-intel

when kata container start fails, netns will leak, add a defer func
to fix it

Fixes: #1640

Signed-off-by: Ace-Tang <aceapril@126.com>
@jodh-intel
Copy link

Thanks @Ace-Tang.

/retest

@lifupan
Copy link
Member

lifupan commented May 10, 2019

Since the failed case "TestHostNetworkingRequested" is not related with the PR, so merged this PR.

@lifupan lifupan merged commit 8386610 into kata-containers:master May 10, 2019
@Ace-Tang
Copy link
Contributor Author

I will try to see if TestHostNetworkingRequested fail can be fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

netns leak issue

7 participants