fix: sse shutdown context

This commit is contained in:
d34dscene
2025-02-18 13:11:10 +01:00
parent 5089d86a24
commit 8729b65e0e
4 changed files with 16 additions and 21 deletions
+9 -1
View File
@@ -17,6 +17,7 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
util.Clients[w] = true
util.ClientsMutex.Unlock()
clientDone := make(chan struct{})
defer func() {
// Unregister the client when the connection is closed
util.ClientsMutex.Lock()
@@ -24,5 +25,12 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
util.ClientsMutex.Unlock()
}()
<-r.Context().Done()
select {
case <-r.Context().Done():
return
case <-util.SSEDone:
return
case <-clientDone:
return
}
}