diff --git a/main.go b/main.go index 254338f..a1fd40a 100644 --- a/main.go +++ b/main.go @@ -221,6 +221,11 @@ func clientHandler(w http.ResponseWriter, r *http.Request) { ch := NewClientChannel(name) defer ch.Close() for { + select { + case <-r.Context().Done(): + fmt.Printf("Connection to client %s closed. Cleanup the channel.\n", remote) + default: + } chunk := <-ch.Data _, err := w.Write(chunk) if err != nil {