Merge pull request #19194 from LK4D4/fix_race_clean_net

Fix race on cleaning endpoint data
This commit is contained in:
Tibor Vass 2016-01-12 13:28:50 -05:00
commit 45211af702
1 changed files with 25 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/image"
"github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/filters"
networktypes "github.com/docker/engine-api/types/network"
"github.com/docker/go-connections/nat"
)
@ -344,7 +345,30 @@ func (daemon *Daemon) transformContainer(container *container.Container, ctx *li
newC.Created = container.Created.Unix()
newC.Status = container.State.String()
newC.HostConfig.NetworkMode = string(container.HostConfig.NetworkMode)
newC.NetworkSettings = &types.SummaryNetworkSettings{container.NetworkSettings.Networks}
// copy networks to avoid races
networks := make(map[string]*networktypes.EndpointSettings)
for name, network := range container.NetworkSettings.Networks {
if network == nil {
continue
}
networks[name] = &networktypes.EndpointSettings{
EndpointID: network.EndpointID,
Gateway: network.Gateway,
IPAddress: network.IPAddress,
IPPrefixLen: network.IPPrefixLen,
IPv6Gateway: network.IPv6Gateway,
GlobalIPv6Address: network.GlobalIPv6Address,
GlobalIPv6PrefixLen: network.GlobalIPv6PrefixLen,
MacAddress: network.MacAddress,
}
if network.IPAMConfig != nil {
networks[name].IPAMConfig = &networktypes.EndpointIPAMConfig{
IPv4Address: network.IPAMConfig.IPv4Address,
IPv6Address: network.IPAMConfig.IPv6Address,
}
}
}
newC.NetworkSettings = &types.SummaryNetworkSettings{Networks: networks}
newC.Ports = []types.Port{}
for port, bindings := range container.NetworkSettings.Ports {