Fix memory leak with websocket not removing unused listeners

This commit is contained in:
Dane Everitt 2020-07-29 21:39:17 -07:00
parent 0b761320cc
commit f0d6f67c6b
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -52,6 +52,7 @@ func (h *Handler) ListenForServerEvents(ctx context.Context) {
h.server.Events().Subscribe(event, eventChannel) h.server.Events().Subscribe(event, eventChannel)
} }
for d := range eventChannel {
select { select {
case <-ctx.Done(): case <-ctx.Done():
for _, event := range events { for _, event := range events {
@ -60,8 +61,6 @@ func (h *Handler) ListenForServerEvents(ctx context.Context) {
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},