PortAllocator: Check if generated port is not already in use or reserved
Change-Id: Ic152e5265fe06b62d8e4e94e8212b02eb42025dd
diff --git a/core/port-allocator/main.go b/core/port-allocator/main.go
index 6b4fd47..3d69ab9 100644
--- a/core/port-allocator/main.go
+++ b/core/port-allocator/main.go
@@ -200,7 +200,9 @@
p := start + int(r.Int64())
ps := strconv.Itoa(p)
if _, ok := pm[ps]; !ok {
- return p, nil
+ if _, ok := reserve[p]; !ok {
+ return p, nil
+ }
}
}
return -1, fmt.Errorf("could not generate random port")