From 8f6a14452dfd88aedc8ac9577a98c38a555baadc Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Mon, 30 Mar 2015 17:39:43 -0700 Subject: [PATCH 1/2] Avoid ServeApi race condition If job "acceptconnections" is called before "serveapi" the API Accept() method will hang forever waiting for activation. This is due to the fact that when "acceptconnections" ran the activation channel was nil. Signed-off-by: Darren Shepherd --- api/server/server.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/server/server.go b/api/server/server.go index a7d0a58b2f..c1b89fcaaf 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -39,7 +39,7 @@ import ( ) var ( - activationLock chan struct{} + activationLock chan struct{} = make(chan struct{}) ) type HttpServer struct { @@ -1593,7 +1593,6 @@ func ServeApi(job *engine.Job) error { protoAddrs = job.Args chErrors = make(chan error, len(protoAddrs)) ) - activationLock = make(chan struct{}) for _, protoAddr := range protoAddrs { protoAddrParts := strings.SplitN(protoAddr, "://", 2) From c71747571458bf992c729c483c9509e8182d630b Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Tue, 31 Mar 2015 15:12:15 -0700 Subject: [PATCH 2/2] Fix panic in integration tests Closing activationLock only if it's not closed already. This is needed only because integration tests using docker code directly and doesn't care about global state. Signed-off-by: Alexander Morozov --- api/server/server_linux.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/server/server_linux.go b/api/server/server_linux.go index 972f5ff74e..0de20a5f11 100644 --- a/api/server/server_linux.go +++ b/api/server/server_linux.go @@ -95,7 +95,9 @@ func AcceptConnections(job *engine.Job) error { go systemd.SdNotify("READY=1") // close the lock so the listeners start accepting connections - if activationLock != nil { + select { + case <-activationLock: + default: close(activationLock) }