mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 <zs.broccoli@gmail.com>
This commit is contained in:
parent
5343ede602
commit
9451cf39ef
1 changed files with 1 additions and 6 deletions
|
@ -15,6 +15,7 @@ type portMap struct {
|
||||||
func newPortMap() *portMap {
|
func newPortMap() *portMap {
|
||||||
return &portMap{
|
return &portMap{
|
||||||
p: map[int]struct{}{},
|
p: map[int]struct{}{},
|
||||||
|
last: EndPortRange,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,12 +136,6 @@ func ReleaseAll() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pm *portMap) findPort() (int, 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++ {
|
for port := pm.last + 1; port != pm.last; port++ {
|
||||||
if port > EndPortRange {
|
if port > EndPortRange {
|
||||||
port = BeginPortRange
|
port = BeginPortRange
|
||||||
|
|
Loading…
Add table
Reference in a new issue