From 44d01e0ba5f7ac57c071334bf6c802b20e0cbc5e Mon Sep 17 00:00:00 2001
From: Manuel Kieweg <manuel.kieweg@h-da.de>
Date: Tue, 30 Mar 2021 14:48:52 +0100
Subject: [PATCH] add mutex fpr httpAPI start

---
 nucleus/controller.go | 5 ++---
 nucleus/http_test.go  | 2 ++
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/nucleus/controller.go b/nucleus/controller.go
index e8fb8413c..169a4ee52 100644
--- a/nucleus/controller.go
+++ b/nucleus/controller.go
@@ -47,7 +47,8 @@ func initialize() error {
 	}
 
 	// TODO: Start grpc listener here
-
+	coreLock.Lock()
+	defer coreLock.Unlock()
 	return httpAPI()
 }
 
@@ -76,11 +77,9 @@ func createPrincipalNetworkDomain(sbi SouthboundInterface) error {
 // Run calls initialize to start the controller
 func Run(ctx context.Context) error {
 	var initError error
-	coreLock.Lock()
 	coreOnce.Do(func() {
 		initError = initialize()
 	})
-	coreLock.Unlock()
 	if initError != nil {
 		log.WithFields(log.Fields{}).Error(initError)
 		return initError
diff --git a/nucleus/http_test.go b/nucleus/http_test.go
index 35ce78254..d6ad288f1 100644
--- a/nucleus/http_test.go
+++ b/nucleus/http_test.go
@@ -137,10 +137,12 @@ func Test_httpApi(t *testing.T) {
 			wantErr: false,
 		},
 	}
+	coreLock.Lock()
 	if err := httpAPI(); err != nil {
 		t.Errorf("httpApi() error = %v", err)
 		return
 	}
+	coreLock.Unlock()
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			got, err := http.Get(tt.request)
-- 
GitLab