Skip to content

Sandbox.SetKey() should not reset the osl sandbox on failure#1700

Merged
sanimej merged 1 commit intomoby:masterfrom
aboch:clr
Apr 11, 2017
Merged

Sandbox.SetKey() should not reset the osl sandbox on failure#1700
sanimej merged 1 commit intomoby:masterfrom
aboch:clr

Conversation

@aboch
Copy link
Copy Markdown
Contributor

@aboch aboch commented Mar 28, 2017

Related to moby/moby/issues/31414

Because the failure would not be on creating the osl sandbox
(which is done by somebody else). It would be on the programming
libnetwork does on the osl sandbox. In case of failure just report
the error. External caller will take care of removing the parent sandbox
via the cleanup on the error handling path. Otherwise the osl sandbox
will never be removed.

Signed-off-by: Alessandro Boch aboch@docker.com

Because the failure would not be on creating the osl sandbox
(which is done by somebody else). It would be on the programming
libnetwork does on the osl sandbox. In case of failure just report
the error. External caller will take care of removing the parent sandbox
via the cleanup on the error handling path. Otherwise the osl sandbox
will never be removed.

Signed-off-by: Alessandro Boch <aboch@docker.com>
Comment thread sandbox.go
sb.Unlock()
defer func() {
if err != nil {
sb.Lock()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldnt we instead perform the cleanup here and not rely on external caller to do the cleanup ?
Its generally a good practice to cleanup any locally allocated resource (GetSandboxForExternalKey) in the defer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Its generally a good practice to cleanup any locally allocated resource

Agree, but the netns is not a locally allocated resource.

SetKey job is in fact to informing libnetwork about the existing netns for the specific Sandbox. So libnetwork must first link the two and this must not change. This is what GetSandboxForExternalKey does, creating the lbnetwork abstraction, handle for the existing netns.

If we instead cleanup what GetSandboxForExternalKey did, then we will loose the handle and we won't be able to remove the netns when docker invokes the Sandbox.Delete().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @aboch. that makes sense.

Comment thread sandbox.go
sb.Unlock()
defer func() {
if err != nil {
sb.Lock()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @aboch. that makes sense.

@sanimej
Copy link
Copy Markdown

sanimej commented Apr 11, 2017

LGTM

@sanimej sanimej merged commit b13e060 into moby:master Apr 11, 2017
liusdu pushed a commit to liusdu/moby that referenced this pull request Oct 30, 2017
Because the failure would not be on creating the osl sandbox
(which is done by somebody else). It would be on the programming
libnetwork does on the osl sandbox. In case of failure just report
the error. External caller will take care of removing the parent sandbox
via the cleanup on the error handling path. Otherwise the osl sandbox
will never be removed.

cherry-pick from moby/libnetwork#1700

Signed-off-by: Alessandro Boch <aboch@docker.com>
Signed-off-by: Lei Jitang <leijitang@huawei.com>
mountkin added a commit to mountkin/docker that referenced this pull request Oct 17, 2018
Upstream PR: moby/libnetwork#1700

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
runcom pushed a commit to projectatomic/docker that referenced this pull request Oct 17, 2018
Upstream PR: moby/libnetwork#1700

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants