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

virtcontainers: always pass sandbox as a pointer#263

Merged
egernst merged 1 commit intokata-containers:masterfrom
bergwolf:sandbox_pointer
May 1, 2018
Merged

virtcontainers: always pass sandbox as a pointer#263
egernst merged 1 commit intokata-containers:masterfrom
bergwolf:sandbox_pointer

Conversation

@bergwolf
Copy link
Copy Markdown
Member

Currently we sometimes pass it as a pointer and other times not. As
a result, the view of sandbox across virtcontainers may not be the same
and it costs extra memory copy each time we pass it by value. Fix it
by ensuring sandbox is always passed by pointers.

Fixes: #262

Signed-off-by: Peng Tao bergwolf@gmail.com


// start is the proxy start implementation for ccProxy.
func (p *ccProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) {
func (p *ccProxy) start(sandbox *Sandbox, params proxyParams) (int, string, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't we now need check on all these params now they are pointers?:

var errNeedSandbox = errors.New("Sandbox cannot be empty")

    :

func (p *ccProxy) start(sandbox *Sandbox, params proxyParams) (int, string, error) {
    if sandbox == nil {
        return -1, "", errNeedSandbox
    }

    :
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These are all internal functions. I think we should trust internal callers because otherwise we do not trust ourselves. That said, even if we do not trust internal callers, the check should be added as a separate PR since it is an existing issue for places where sandbox is already passed as pointer.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call me paranoid, but I'd honestly take the opposite approach and not trust anything! 😄

imho we need to "fail fast" since if we start trusting ourselves, we get into horrible situations where func1 calls func2 calls funcN, and funcN explodes because func1 forgot to check if sandbox == nil. That makes debugging very difficult. This is not theoretical - we've been in that situation before in the very early days of vc which prompted me to raise PRs such as containers/virtcontainers#163.

We also have precedent for checking all parameters, for example:

How about adding such checks on a new commit on this PR to ensure those checks get applied and the issue doesn't just get lost in the backlog?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@jodh-intel Do you want to check every parameter in every function? Since that's what not trust anything means to me. From my point of view, I think we should check all parameters in all of the virtcontainers APIs but that's all. We are already doing this and it ensures that we fail fast.

OTOH, if we do not trust ourselves and check parameter in every function, we waste CPU time and memory on checking the same thing over and over again. Please create an issue for it if you think that's really necessary. I don't mind having such a discussion but it does not need to block this PR since it's a different/existing issue.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A few examples of where *Sandbox is not checked before being dereferenced in master:

There a more of them for sure. And if we want to take precaution in all these functions, it should also apply to other parameters as well, not just the sandbox pointers.

@bergwolf
Copy link
Copy Markdown
Member Author

Jenkins failed on kata-containers/tests#264

@jcvenegas
Copy link
Copy Markdown
Member

Please push again, now the test is skipped.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 27, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@8d897f4). Click here to learn what that means.
The diff coverage is 68.25%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #263   +/-   ##
=========================================
  Coverage          ?   65.58%           
=========================================
  Files             ?       74           
  Lines             ?     7932           
  Branches          ?        0           
=========================================
  Hits              ?     5202           
  Misses            ?     2169           
  Partials          ?      561
Impacted Files Coverage Δ
virtcontainers/agent.go 92.15% <ø> (ø)
virtcontainers/kata_builtin_proxy.go 0% <0%> (ø)
virtcontainers/kata_builtin_shim.go 0% <0%> (ø)
virtcontainers/kata_proxy.go 0% <0%> (ø)
virtcontainers/noop_proxy.go 100% <100%> (ø)
virtcontainers/mount.go 79.86% <100%> (ø)
virtcontainers/cni.go 61.84% <100%> (ø)
virtcontainers/proxy.go 97.18% <100%> (ø)
virtcontainers/kata_shim.go 70% <100%> (ø)
virtcontainers/filesystem.go 68.39% <100%> (ø)
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d897f4...5fb4768. Read the comment docs.

@bergwolf
Copy link
Copy Markdown
Member Author

CI green. @sboeuf @egernst @jodh-intel @laijs PTAL.

Copy link
Copy Markdown

@devimc devimc left a comment

Choose a reason for hiding this comment

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

lgtm

@bergwolf
Copy link
Copy Markdown
Member Author

@jodh-intel can we merge this?

@sboeuf
Copy link
Copy Markdown

sboeuf commented Apr 30, 2018

@bergwolf I know you need this PR to be merged in order to move forward with #252.
But we should definitely follow @jodh-intel comments and add some checks to the codebase. The introduction of pointers has to be backed up by some better testing of the sandbox pointers.

Also, I know, as you mentioned it, that we might not check it properly in functions where it is already a pointer, that's why I propose that you can open an issue tracking this as a global thing to address through the entire codebase, marking this as high priority.

In the meantime, I am okay to merge this one, but I'd like @egernst and @amshinde feedbacks on this.

BTW, you need to rebase it before we can merge it.

Copy link
Copy Markdown
Member

@egernst egernst left a comment

Choose a reason for hiding this comment

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

I am okay with discussing checks in a separate issue and follow in PR pending the discussion.

@bergwolf - can you rebase?

Currently we sometimes pass it as a pointer and other times not. As
a result, the view of sandbox across virtcontainers may not be the same
and it costs extra memory copy each time we pass it by value. Fix it
by ensuring sandbox is always passed by pointers.

Fixes: kata-containers#262

Signed-off-by: Peng Tao <bergwolf@gmail.com>
@bergwolf bergwolf force-pushed the sandbox_pointer branch from a8caa41 to 5fb4768 Compare May 1, 2018 12:51
@bergwolf
Copy link
Copy Markdown
Member Author

bergwolf commented May 1, 2018

@jodh-intel @egernst @sboeuf PR rebased and #280 is created to follow up the sanity check discussion.

@grahamwhaley
Copy link
Copy Markdown
Contributor

@egernst @sboeuf @bergwolf - this is GREEN now - if we are not wanting to merge right now, please put a DNM on it - or somebody is going to press that button....

@egernst egernst merged commit 70b3c77 into kata-containers:master May 1, 2018
Copy link
Copy Markdown
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.

lgtm

@egernst
Copy link
Copy Markdown
Member

egernst commented May 1, 2018

Too late :)

@bergwolf bergwolf deleted the sandbox_pointer branch September 13, 2018 03:28
zklei pushed a commit to zklei/runtime that referenced this pull request Jun 13, 2019
…live

yamux: disable yamux keep alive in server channel
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.

8 participants