зеркало из https://github.com/microsoft/docker.git
Fix a race condition when running the port allocator
This commit is contained in:
Родитель
a4fc52305a
Коммит
d32f184696
|
@ -167,10 +167,6 @@ type PortAllocator struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (alloc *PortAllocator) runFountain() {
|
func (alloc *PortAllocator) runFountain() {
|
||||||
if alloc.fountain != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
alloc.fountain = make(chan int)
|
|
||||||
for {
|
for {
|
||||||
for port := portRangeStart; port < portRangeEnd; port++ {
|
for port := portRangeStart; port < portRangeEnd; port++ {
|
||||||
alloc.fountain <- port
|
alloc.fountain <- port
|
||||||
|
@ -208,6 +204,7 @@ func (alloc *PortAllocator) Acquire(port int) (int, error) {
|
||||||
func newPortAllocator() (*PortAllocator, error) {
|
func newPortAllocator() (*PortAllocator, error) {
|
||||||
allocator := &PortAllocator{
|
allocator := &PortAllocator{
|
||||||
inUse: make(map[int]struct{}),
|
inUse: make(map[int]struct{}),
|
||||||
|
fountain: make(chan int),
|
||||||
}
|
}
|
||||||
go allocator.runFountain()
|
go allocator.runFountain()
|
||||||
return allocator, nil
|
return allocator, nil
|
||||||
|
|
Загрузка…
Ссылка в новой задаче