Skip to content
Snippets Groups Projects
Commit b636a139 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

fixed race conditions

parent a71d4d59
No related branches found
No related tags found
3 merge requests!123Refactor container deployment,!122Resolve "Data Race HTTP API",!90Develop
Pipeline #67388 passed with warnings
...@@ -47,19 +47,8 @@ func initialize() error { ...@@ -47,19 +47,8 @@ func initialize() error {
} }
// TODO: Start grpc listener here // TODO: Start grpc listener here
if err := httpAPI(); err != nil {
return err
}
attachDatabase()
return nil
}
// deprecated return httpAPI()
// attachDatabase connects to the database and passes the connection to the controller core
func attachDatabase() {
c.database = database.NewDatabaseClient()
} }
// createSouthboundInterfaces initializes the controller with its supported SBIs // createSouthboundInterfaces initializes the controller with its supported SBIs
......
...@@ -9,12 +9,9 @@ import ( ...@@ -9,12 +9,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net/http" "net/http"
"net/url" "net/url"
"sync"
"time" "time"
) )
var httpOnce sync.Once
func stopHttpServer() error { func stopHttpServer() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
...@@ -35,15 +32,10 @@ func registerHttpHandler() { ...@@ -35,15 +32,10 @@ func registerHttpHandler() {
// deprecated // deprecated
func httpAPI() (err error) { func httpAPI() (err error) {
coreLock.Lock() registerHttpHandler()
defer coreLock.Unlock()
httpOnce.Do(registerHttpHandler)
c.httpServer = &http.Server{Addr: ":8080"} c.httpServer = &http.Server{Addr: ":8080"}
go func() { go func() {
err = c.httpServer.ListenAndServe() log.Info(c.httpServer.ListenAndServe())
if err != nil {
return
}
}() }()
return nil return nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment