Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -35,7 +35,6 @@ var ( |
| 35 | 35 |
defaultIP = net.ParseIP("0.0.0.0")
|
| 36 | 36 |
once sync.Once |
| 37 | 37 |
instance *PortAllocator |
| 38 |
- createInstance = func() { instance = newInstance() }
|
|
| 39 | 38 |
) |
| 40 | 39 |
|
| 41 | 40 |
// ErrPortAlreadyAllocated is the returned error information when a requested port is already being used |
| ... | ... |
@@ -99,7 +98,9 @@ func Get() *PortAllocator {
|
| 99 | 99 |
// the OS so that it can have up to date view of the OS port allocation. |
| 100 | 100 |
// When this happens singleton behavior will be removed. Clients do not |
| 101 | 101 |
// need to worry about this, they will not see a change in behavior. |
| 102 |
- once.Do(createInstance) |
|
| 102 |
+ once.Do(func() {
|
|
| 103 |
+ instance = newInstance() |
|
| 104 |
+ }) |
|
| 103 | 105 |
return instance |
| 104 | 106 |
} |
| 105 | 107 |
|
| ... | ... |
@@ -199,15 +200,10 @@ func (p *PortAllocator) SetPortRange(portBegin, portEnd int) error {
|
| 199 | 199 |
var err error |
| 200 | 200 |
if portBegin == 0 && portEnd == 0 {
|
| 201 | 201 |
begin, end = getDefaultPortRange() |
| 202 |
- |
|
| 203 |
- } else {
|
|
| 204 |
- begin, end, err = sanitizePortRange(portBegin, portEnd) |
|
| 205 |
- if err != nil {
|
|
| 206 |
- return err |
|
| 207 |
- } |
|
| 202 |
+ } else if begin, end, err = sanitizePortRange(portBegin, portEnd); err != nil {
|
|
| 203 |
+ return err |
|
| 208 | 204 |
} |
| 209 |
- logrus.Debugf("Setting up port allocator to range %v-%v, current %v-%v",
|
|
| 210 |
- begin, end, p.Begin, p.End) |
|
| 205 |
+ logrus.Debugf("Setting up port allocator to range %v-%v, current %v-%v", begin, end, p.Begin, p.End)
|
|
| 211 | 206 |
p.mutex.Lock() |
| 212 | 207 |
defer p.mutex.Unlock() |
| 213 | 208 |
if p.Begin == begin && p.End == end {
|