Skip to content

allocateNetwork: fix network sandbox not cleaned up on failure#41020

Merged
tiborvass merged 2 commits intomoby:masterfrom
thaJeztah:fix_sandbox_cleanup
Jun 5, 2020
Merged

allocateNetwork: fix network sandbox not cleaned up on failure#41020
tiborvass merged 2 commits intomoby:masterfrom
thaJeztah:fix_sandbox_cleanup

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah commented May 25, 2020

The defer function was checking for the local err variable, not on the error that was returned by the function. As a result, the sandbox would never be cleaned up for containers that used "none" networking, and a failiure occured during setup.

The second commit is a small refactor; allocateNetwork() can return early, in which case these variables were unused, so assign them later in the function.

Looks like this was introduced in #31996 (which was created to address #31597)

- Description for the changelog

thaJeztah added 2 commits May 25, 2020 14:10
The defer function was checking for the local `err` variable, not
on the error that was returned by the function. As a result, the
sandbox would never be cleaned up for containers that used "none"
networking, and a failiure occured during setup.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
allocateNetwork() can return early, in which case these variables were unused.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
Copy link
Copy Markdown
Member Author

@arkodg @xinfengliu @AkihiroSuda PTAL

Copy link
Copy Markdown
Contributor

@xinfengliu xinfengliu left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@@ -594,7 +596,7 @@ func (daemon *Daemon) allocateNetwork(container *container.Container) error {
}
updateSandboxNetworkSettings(container, sb)
defer func() {
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.

The purpose of defer here is to handle the err in following container.WriteHostConfig(). You are right @thaJeztah .

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.

Yes, it's very easy to overlook the problem. My eye just fell on it, and I thought: "that doesn't look right!"

Copy link
Copy Markdown
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM

@tiborvass tiborvass merged commit 5ffd677 into moby:master Jun 5, 2020
@thaJeztah thaJeztah deleted the fix_sandbox_cleanup branch June 8, 2020 10:03
@thaJeztah thaJeztah added this to the 20.03.0 milestone Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants