diff --git a/cni/network/network_windows.go b/cni/network/network_windows.go index d839fa0175..615c871496 100644 --- a/cni/network/network_windows.go +++ b/cni/network/network_windows.go @@ -42,12 +42,16 @@ func handleConsecutiveAdd(args *cniSkel.CmdArgs, endpointId string, nwInfo *netw hnsEndpoint, err := hcsshim.GetHNSEndpointByName(endpointId) if hnsEndpoint != nil { log.Printf("[net] Found existing endpoint through hcsshim: %+v", hnsEndpoint) - log.Printf("[net] Attaching ep %v to container %v", hnsEndpoint.Id, args.ContainerID) - - err := hcsshim.HotAttachEndpoint(args.ContainerID, hnsEndpoint.Id) - if err != nil { - log.Printf("[cni-net] Failed to hot attach shared endpoint[%v] to container [%v], err:%v.", hnsEndpoint.Id, args.ContainerID, err) - return nil, err + endpoint, _ := hcsshim.GetHNSEndpointByID(hnsEndpoint.Id) + isAttached, _ := endpoint.IsAttached(args.ContainerID) + // Attach endpoint if it's not attached yet. + if !isAttached { + log.Printf("[net] Attaching ep %v to container %v", hnsEndpoint.Id, args.ContainerID) + err := hcsshim.HotAttachEndpoint(args.ContainerID, hnsEndpoint.Id) + if err != nil { + log.Printf("[cni-net] Failed to hot attach shared endpoint[%v] to container [%v], err:%v.", hnsEndpoint.Id, args.ContainerID, err) + return nil, err + } } // Populate result.