Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit f9e6b4e

Browse files
authored
Fixing race conditions (#1096)
1 parent 41392ce commit f9e6b4e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

quesma/frontend_connectors/basic_http_frontend_connector.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import (
1111
"io"
1212
"net/http"
1313
quesma_api "quesma_v2/core"
14+
"sync"
1415
)
1516

1617
type BasicHTTPFrontendConnector struct {
17-
listener *http.Server
18-
router quesma_api.Router
19-
18+
listener *http.Server
19+
router quesma_api.Router
20+
mutex sync.Mutex
2021
responseMutator func(w http.ResponseWriter) http.ResponseWriter
2122
endpoint string
2223
}
@@ -80,6 +81,12 @@ func getMatchingHandler(requestPath string, handlers map[string]quesma_api.Handl
8081
}
8182

8283
func (h *BasicHTTPFrontendConnector) Listen() error {
84+
h.mutex.Lock()
85+
defer h.mutex.Unlock()
86+
if h.listener != nil {
87+
// TODO handle this gracefully and return correct error
88+
return nil
89+
}
8390
h.listener = &http.Server{}
8491
h.listener.Addr = h.endpoint
8592
h.listener.Handler = h
@@ -93,6 +100,8 @@ func (h *BasicHTTPFrontendConnector) Listen() error {
93100
}
94101

95102
func (h *BasicHTTPFrontendConnector) Stop(ctx context.Context) error {
103+
h.mutex.Lock()
104+
defer h.mutex.Unlock()
96105
if h.listener == nil {
97106
return nil
98107
}

0 commit comments

Comments
 (0)