Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Engquist <[email protected]>
  • Loading branch information
Jim Engquist committed Jan 14, 2019
1 parent 252a619 commit 92dc64d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions goapi/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,23 +330,18 @@ func websocketHandler(w http.ResponseWriter, r *http.Request) {
defer conn.Close()

log.Debug("created websocket connection")
statusChan := makeStatusWriter(conn)
defer func() {
log.Debug("closing statusChan for closed websocket")
close(statusChan)
}()

// Keep track of most recent subscription. If a subscription is active
// when websocket closes we could end up closing statusChan without
// having removed it from listener list
subscribed := ""
statusChan := makeStatusWriter(conn)
defer func() {
// N.B. defer's are executed in LIFO order so this should
// run before we close statusChan
if subscribed != "" {
log.Warnf("removing listener for '%s' on websocket close", subscribed)
removeListener(subscribed, statusChan)
}
log.Debug("closing statusChan for closed websocket")
close(statusChan)
}()

for {
Expand Down

0 comments on commit 92dc64d

Please sign in to comment.