瀏覽代碼

Fix a race condition when running the port allocator

Solomon Hykes 12 年之前
父節點
當前提交
d32f184696
共有 1 個文件被更改,包括 1 次插入4 次删除
  1. 1 4
      network.go

+ 1 - 4
network.go

@@ -167,10 +167,6 @@ type PortAllocator struct {
 }
 
 func (alloc *PortAllocator) runFountain() {
-	if alloc.fountain != nil {
-		return
-	}
-	alloc.fountain = make(chan int)
 	for {
 		for port := portRangeStart; port < portRangeEnd; port++ {
 			alloc.fountain <- port
@@ -208,6 +204,7 @@ func (alloc *PortAllocator) Acquire(port int) (int, error) {
 func newPortAllocator() (*PortAllocator, error) {
 	allocator := &PortAllocator{
 		inUse: make(map[int]struct{}),
+		fountain: make(chan int),
 	}
 	go allocator.runFountain()
 	return allocator, nil