mirror of
https://github.com/docker/cli.git
synced 2026-01-18 08:21:31 +03:00
Merge pull request #11958 from LK4D4/fix_portmapper_race
Move portmapper initialization to var block Upstream-commit: b85cf5da5e27014ff2e5499d91168678c5c99caa Component: engine
This commit is contained in:
@@ -78,12 +78,19 @@ var (
|
||||
bridgeIPv6Addr net.IP
|
||||
globalIPv6Network *net.IPNet
|
||||
portMapper *portmapper.PortMapper
|
||||
once sync.Once
|
||||
|
||||
defaultBindingIP = net.ParseIP("0.0.0.0")
|
||||
currentInterfaces = ifaces{c: make(map[string]*networkInterface)}
|
||||
ipAllocator = ipallocator.New()
|
||||
)
|
||||
|
||||
func initPortMapper() {
|
||||
once.Do(func() {
|
||||
portMapper = portmapper.New()
|
||||
})
|
||||
}
|
||||
|
||||
func InitDriver(job *engine.Job) error {
|
||||
var (
|
||||
networkv4 *net.IPNet
|
||||
@@ -100,7 +107,7 @@ func InitDriver(job *engine.Job) error {
|
||||
fixedCIDR = job.Getenv("FixedCIDR")
|
||||
fixedCIDRv6 = job.Getenv("FixedCIDRv6")
|
||||
)
|
||||
portMapper = portmapper.New()
|
||||
initPortMapper()
|
||||
|
||||
if defaultIP := job.Getenv("DefaultBindingIP"); defaultIP != "" {
|
||||
defaultBindingIP = net.ParseIP(defaultIP)
|
||||
@@ -353,6 +360,7 @@ func setupIPTables(addr net.Addr, icc, ipmasq bool) error {
|
||||
}
|
||||
|
||||
func RequestPort(ip net.IP, proto string, port int) (int, error) {
|
||||
initPortMapper()
|
||||
return portMapper.Allocator.RequestPort(ip, proto, port)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user