From b636a1399d1e868a6f625e81c075184ddfb38a6c Mon Sep 17 00:00:00 2001
From: Manuel Kieweg <manuel.kieweg@h-da.de>
Date: Mon, 29 Mar 2021 14:50:56 +0100
Subject: [PATCH] fixed race conditions

---
 nucleus/controller.go | 13 +------------
 nucleus/http.go       | 12 ++----------
 2 files changed, 3 insertions(+), 22 deletions(-)

diff --git a/nucleus/controller.go b/nucleus/controller.go
index bb928f4ae..fc832735f 100644
--- a/nucleus/controller.go
+++ b/nucleus/controller.go
@@ -47,19 +47,8 @@ func initialize() error {
 	}
 
 	// TODO: Start grpc listener here
-	if err := httpAPI(); err != nil {
-		return err
-	}
-
-	attachDatabase()
-
-	return nil
-}
 
-// deprecated
-// attachDatabase connects to the database and passes the connection to the controller core
-func attachDatabase() {
-	c.database = database.NewDatabaseClient()
+	return httpAPI()
 }
 
 // createSouthboundInterfaces initializes the controller with its supported SBIs
diff --git a/nucleus/http.go b/nucleus/http.go
index 41fea9aaa..1869f27e7 100644
--- a/nucleus/http.go
+++ b/nucleus/http.go
@@ -9,12 +9,9 @@ import (
 	log "github.com/sirupsen/logrus"
 	"net/http"
 	"net/url"
-	"sync"
 	"time"
 )
 
-var httpOnce sync.Once
-
 func stopHttpServer() error {
 	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
 	defer cancel()
@@ -35,15 +32,10 @@ func registerHttpHandler() {
 
 // deprecated
 func httpAPI() (err error) {
-	coreLock.Lock()
-	defer coreLock.Unlock()
-	httpOnce.Do(registerHttpHandler)
+	registerHttpHandler()
 	c.httpServer = &http.Server{Addr: ":8080"}
 	go func() {
-		err = c.httpServer.ListenAndServe()
-		if err != nil {
-			return
-		}
+		log.Info(c.httpServer.ListenAndServe())
 	}()
 	return nil
 }
-- 
GitLab