From 79574eea31109e4c01ed9feb443eb74c031081dd Mon Sep 17 00:00:00 2001 From: shuai-z Date: Tue, 21 Oct 2014 12:24:01 +0800 Subject: [PATCH] Port number 49153(BeginPortRange) would be returned twice, causing duplication and potential errors. If we first request port 49153 (BeginPortRange) explicitly, and later some time request the next free port (of same ip/proto) by calling RequestPort() with port number 0, we will again get 49153 returned, even if it's currently in use. Because findPort() blindly retured BeginPortRange the first run, without checking if it has already been taken. Signed-off-by: shuai-z Upstream-commit: 9451cf39eff037eccb04319c1e601d08495cab3c Component: engine --- .../daemon/networkdriver/portallocator/portallocator.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/components/engine/daemon/networkdriver/portallocator/portallocator.go b/components/engine/daemon/networkdriver/portallocator/portallocator.go index d4fcc6e725..c6e8a66e8d 100644 --- a/components/engine/daemon/networkdriver/portallocator/portallocator.go +++ b/components/engine/daemon/networkdriver/portallocator/portallocator.go @@ -15,6 +15,7 @@ type portMap struct { func newPortMap() *portMap { return &portMap{ p: map[int]struct{}{}, + last: EndPortRange, } } @@ -135,12 +136,6 @@ func ReleaseAll() error { } func (pm *portMap) findPort() (int, error) { - if pm.last == 0 { - pm.p[BeginPortRange] = struct{}{} - pm.last = BeginPortRange - return BeginPortRange, nil - } - for port := pm.last + 1; port != pm.last; port++ { if port > EndPortRange { port = BeginPortRange