- commit
- 1a9a661732c30925d383d1b51f8d93f0ebb3effe
- parent
- da546827545672c2fb575e0f65cc08d1710ad53e
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2025-06-13 14:53
concurrency: drain channel on unsubscribe
Diffstat
| M | via.go | 8 | +++++++- |
1 files changed, 7 insertions, 1 deletions
diff --git a/via.go b/via.go
@@ -132,6 +132,7 @@ func (topic *Topic) run(key string) {
132 132
133 133 topic.channels[sub.ch] = true
134 134 case ch := <-topic.unsubChan:
-1 135 close(ch)
135 136 delete(topic.channels, ch)
136 137 case post := <-topic.postChan:
137 138 topic.lastId += 1
@@ -240,7 +241,12 @@ func get(w http.ResponseWriter, r *http.Request) {
240 241 select {
241 242 case <-ctx.Done():
242 243 log.Println("lost a connection on", r.URL.Path)
243 -1 topic.unsubChan <- ch
-1 244 go func() {
-1 245 topic.unsubChan <- ch
-1 246 }()
-1 247 for _ = range ch {
-1 248 // drain channel until unusub closes it
-1 249 }
244 250 return
245 251 case <-ticker.C:
246 252 fmt.Fprintf(w, ": ping\n\n")