Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in initializeNetwork() #17558

Merged
merged 1 commit into from Nov 2, 2015
Merged

Fix bug in initializeNetwork() #17558

merged 1 commit into from Nov 2, 2015

Conversation

aboch
Copy link
Contributor

@aboch aboch commented Oct 31, 2015

  • On docker run --net <network id> ...
    the bug would cause the container to attempt
    to connect to the network two times
  • Also made sure endpoint creation rollback will
    be executed on failures in func (container *Container) connectToNetwork()

Fixes #17543

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

@@ -1007,13 +1013,15 @@ func (container *Container) connectToNetwork(idOrName string, updateSettings boo
}
}()

if err := container.updateEndpointNetworkSettings(n, ep); err != nil {
if err = container.updateEndpointNetworkSettings(n, ep); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Uh-oh, that's why I'm fan of named return handling in defers. Because someone new will write := 100%

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. defers with := is a bad combination and it has tripped us once in the past.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LK4D4
I agree that naked return would also help. But by experience we noticed that from a code clarity standpoint, it is not optimal to use naked return in functions bigger than an handful of lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

@aboch for the sake of consistency with daemon/container.go, I think it would be good to follow @LK4D4's suggestion.

@tiborvass tiborvass self-assigned this Nov 1, 2015
@thaJeztah thaJeztah added this to the 1.9.1 milestone Nov 1, 2015
@aboch
Copy link
Contributor Author

aboch commented Nov 2, 2015

@mavenugo Addressed your comment. PTAL.

@aboch
Copy link
Contributor Author

aboch commented Nov 2, 2015

@LK4D4 Taken care of your comment. PTAL when you get a chance.

@vdemeester
Copy link
Member

@aboch golint issue :

daemon/container_unix.go:920:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)

@aboch
Copy link
Contributor Author

aboch commented Nov 2, 2015

Thanks @vdemeester. Taken care of the golint issue. PTAL.

@calavera
Copy link
Contributor

calavera commented Nov 2, 2015

LGTM. Janky error is unrelated.

@@ -914,6 +914,16 @@ func (container *Container) allocateNetwork() error {
if mode.IsDefault() {
networkName = controller.Config().Daemon.DefaultNetwork
}
if mode.IsUserDefined() {
var (
Copy link
Member

Choose a reason for hiding this comment

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

Can we get rid of this var block and instead do

n, err := condainer.daemon...;
if err != nil {
    return err
}
networkName = n.Name()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.
Let me take care of it.

Thanks

- On `docker run --net <network id> ...`
  the bug would cause the container to attempt
  to connect to the network two times
- Also made sure endpoint creation rollback will
  be executed on failures in `func (container *Container) connectToNetwork()`

Signed-off-by: Alessandro Boch <aboch@docker.com>
@cpuguy83
Copy link
Member

cpuguy83 commented Nov 2, 2015

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants