vc: fix netns leak#1641
Conversation
pkg/katautils/create.go
Outdated
| ns := sandboxConfig.NetworkConfig | ||
| if err != nil && ns.NetNsCreated { | ||
| if ex := cleanupNetNS(ns.NetNSPath); ex != nil { | ||
| kataUtilsLogger.Warnf("Failed to cleanup netns %s", ns.NetNSPath) |
There was a problem hiding this comment.
please use WithField in all the logs to avoid using format specifiers. for example
kataUtilsLogger.WithField("path", ns.NetNSPath).Warn("Failed to cleanup netns")
pkg/katautils/network.go
Outdated
|
|
||
| err = n.Close() | ||
| if err != nil { | ||
| return err |
There was a problem hiding this comment.
Can you return a more verbose message here : "Failed to close netns: %s"
|
/test |
pkg/katautils/create.go
Outdated
| 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") |
There was a problem hiding this comment.
Could you tweak this slightly to also include the error:
kataUtilsLogger.WithField("path", ns.NetNSPath).WithError(ex).Warn("Failed to cleanup netns")There was a problem hiding this comment.
Oh, yes , forget to log error
|
I've nudged a few CI rebuilds. |
pkg/katautils/create.go
Outdated
| 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") |
There was a problem hiding this comment.
You might find that the CI linters complain as errors should start with a lower-case letter (same comment for errors below...)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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 }
There was a problem hiding this comment.
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)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>
|
Thanks @Ace-Tang. /retest |
|
Since the failed case "TestHostNetworkingRequested" is not related with the PR, so merged this PR. |
|
I will try to see if |
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