virtcontainers: always pass sandbox as a pointer#263
virtcontainers: always pass sandbox as a pointer#263egernst merged 1 commit intokata-containers:masterfrom
Conversation
|
|
||
| // 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) { |
There was a problem hiding this comment.
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
}
:
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
A few examples of where *Sandbox is not checked before being dereferenced in master:
- https://github.com/kata-containers/runtime/blob/master/virtcontainers/kata_agent.go#L132
- https://github.com/kata-containers/runtime/blob/master/virtcontainers/kata_agent.go#L183
- https://github.com/kata-containers/runtime/blob/master/virtcontainers/shim.go#L175
- https://github.com/kata-containers/runtime/blob/master/virtcontainers/container.go#L404
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.
|
Jenkins failed on kata-containers/tests#264 |
|
Please push again, now the test is skipped. |
Codecov Report
@@ Coverage Diff @@
## master #263 +/- ##
=========================================
Coverage ? 65.58%
=========================================
Files ? 74
Lines ? 7932
Branches ? 0
=========================================
Hits ? 5202
Misses ? 2169
Partials ? 561
Continue to review full report at Codecov.
|
|
CI green. @sboeuf @egernst @jodh-intel @laijs PTAL. |
|
@jodh-intel can we merge this? |
|
@bergwolf I know you need this PR to be merged in order to move forward with #252. 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. |
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>
|
@jodh-intel @egernst @sboeuf PR rebased and #280 is created to follow up the sanity check discussion. |
|
Too late :) |
…live yamux: disable yamux keep alive in server channel
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