Skip to content

Commit

Permalink
Fix configuration loss when handling concurrent requests (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnjooiopa authored Feb 23, 2024
1 parent 5fa31fe commit 19cd207
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/streams/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,15 @@ func streamsHandler(w http.ResponseWriter, r *http.Request) {
// Not sure about all this API. Should be rewrited...
switch r.Method {
case "GET":
streamsMu.RLock()
defer streamsMu.RUnlock()

api.ResponsePrettyJSON(w, streams[src])

case "PUT":
apiMu.Lock()
defer apiMu.Unlock()

name := query.Get("name")
if name == "" {
name = src
Expand Down Expand Up @@ -198,6 +204,9 @@ func streamsHandler(w http.ResponseWriter, r *http.Request) {
}

case "DELETE":
apiMu.Lock()
defer apiMu.Unlock()

delete(streams, src)

if err := app.PatchConfig(src, nil, "streams"); err != nil {
Expand All @@ -208,4 +217,5 @@ func streamsHandler(w http.ResponseWriter, r *http.Request) {

var log zerolog.Logger
var streams = map[string]*Stream{}
var streamsMu sync.Mutex
var streamsMu sync.RWMutex
var apiMu sync.Mutex

0 comments on commit 19cd207

Please sign in to comment.