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

[Backport 17.06] Possible race on ingress programming #2195

Merged
merged 1 commit into from
Jun 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions service_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const ingressChain = "DOCKER-INGRESS"

var (
ingressOnce sync.Once
ingressProxyMu sync.Mutex
ingressMu sync.Mutex // lock for operations on ingress
ingressProxyTbl = make(map[string]io.Closer)
portConfigMu sync.Mutex
portConfigTbl = make(map[PortConfig]int)
Expand Down Expand Up @@ -327,6 +327,9 @@ func programIngress(gwIP net.IP, ingressPorts []*PortConfig, isDelete bool) erro
addDelOpt = "-D"
}

ingressMu.Lock()
defer ingressMu.Unlock()

chainExists := iptables.ExistChain(ingressChain, iptables.Nat)
filterChainExists := iptables.ExistChain(ingressChain, iptables.Filter)

Expand Down Expand Up @@ -496,13 +499,11 @@ func plumbProxy(iPort *PortConfig, isDelete bool) error {

portSpec := fmt.Sprintf("%d/%s", iPort.PublishedPort, strings.ToLower(PortConfig_Protocol_name[int32(iPort.Protocol)]))
if isDelete {
ingressProxyMu.Lock()
if listener, ok := ingressProxyTbl[portSpec]; ok {
if listener != nil {
listener.Close()
}
}
ingressProxyMu.Unlock()

return nil
}
Expand All @@ -518,9 +519,7 @@ func plumbProxy(iPort *PortConfig, isDelete bool) error {
return err
}

ingressProxyMu.Lock()
ingressProxyTbl[portSpec] = l
ingressProxyMu.Unlock()

return nil
}
Expand Down