Fix memory leak with websocket not removing unused listeners
This commit is contained in:
parent
0b761320cc
commit
f0d6f67c6b
|
@ -52,16 +52,15 @@ func (h *Handler) ListenForServerEvents(ctx context.Context) {
|
||||||
h.server.Events().Subscribe(event, eventChannel)
|
h.server.Events().Subscribe(event, eventChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
for d := range eventChannel {
|
||||||
case <-ctx.Done():
|
select {
|
||||||
for _, event := range events {
|
case <-ctx.Done():
|
||||||
h.server.Events().Unsubscribe(event, eventChannel)
|
for _, event := range events {
|
||||||
}
|
h.server.Events().Unsubscribe(event, eventChannel)
|
||||||
|
}
|
||||||
|
|
||||||
close(eventChannel)
|
close(eventChannel)
|
||||||
default:
|
default:
|
||||||
// Listen for different events emitted by the server and respond to them appropriately.
|
|
||||||
for d := range eventChannel {
|
|
||||||
h.SendJson(&Message{
|
h.SendJson(&Message{
|
||||||
Event: d.Topic,
|
Event: d.Topic,
|
||||||
Args: []string{d.Data},
|
Args: []string{d.Data},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user