Browse Source

Merge pull request #11967 from LK4D4/fix_panic

Avoid ServeApi race condition
Jessie Frazelle 10 years ago
parent
commit
596ddef7d7
2 changed files with 4 additions and 3 deletions
  1. 1 2
      api/server/server.go
  2. 3 1
      api/server/server_linux.go

+ 1 - 2
api/server/server.go

@@ -32,7 +32,7 @@ import (
 )
 )
 
 
 var (
 var (
-	activationLock chan struct{}
+	activationLock chan struct{} = make(chan struct{})
 )
 )
 
 
 type HttpServer struct {
 type HttpServer struct {
@@ -1445,7 +1445,6 @@ func ServeApi(job *engine.Job) error {
 		protoAddrs = job.Args
 		protoAddrs = job.Args
 		chErrors   = make(chan error, len(protoAddrs))
 		chErrors   = make(chan error, len(protoAddrs))
 	)
 	)
-	activationLock = make(chan struct{})
 
 
 	for _, protoAddr := range protoAddrs {
 	for _, protoAddr := range protoAddrs {
 		protoAddrParts := strings.SplitN(protoAddr, "://", 2)
 		protoAddrParts := strings.SplitN(protoAddr, "://", 2)

+ 3 - 1
api/server/server_linux.go

@@ -82,7 +82,9 @@ func AcceptConnections(job *engine.Job) error {
 	// Tell the init daemon we are accepting requests
 	// Tell the init daemon we are accepting requests
 	go systemd.SdNotify("READY=1")
 	go systemd.SdNotify("READY=1")
 	// close the lock so the listeners start accepting connections
 	// close the lock so the listeners start accepting connections
-	if activationLock != nil {
+	select {
+	case <-activationLock:
+	default:
 		close(activationLock)
 		close(activationLock)
 	}
 	}
 	return nil
 	return nil