Skip to content

Commit

Permalink
cleanup: replace deprecated CloseNotifier with ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Nov 3, 2021
1 parent 43e6ea3 commit 9fe73a6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions daemon.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vproxy

import (
"context"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -211,15 +212,14 @@ func (d *Daemon) streamLogs(w http.ResponseWriter, r *http.Request) {
}

// runs forever until connection closes
d.relayLogsUntilClose(flusher, logChan, rw, w)
d.relayLogsUntilClose(flusher, logChan, w, r.Context())
}

func (d *Daemon) relayLogsUntilClose(flusher http.Flusher, logChan chan string, rw http.ResponseWriter, w http.ResponseWriter) {
func (d *Daemon) relayLogsUntilClose(flusher http.Flusher, logChan chan string, w http.ResponseWriter, reqCtx context.Context) {
// Listen to connection close and un-register logChan
notify := rw.(http.CloseNotifier).CloseNotify()
for {
select {
case <-notify:
case <-reqCtx.Done():
return
case line := <-logChan:
fmt.Fprintln(w, line)
Expand Down

0 comments on commit 9fe73a6

Please sign in to comment.