Skip to content

Commit

Permalink
fix CloseNotify called after ServeHTTP finished bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar committed Nov 2, 2016
1 parent 600c5aa commit 7bfa598
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion metad.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,10 @@ func (m *Metad) handleWrapper(handler handleFunc) func(w http.ResponseWriter, re
ctx := context.WithValue(req.Context(), "requestID", requestID)
cancelCtx, cancelFun := context.WithCancel(ctx)
if x, ok := w.(http.CloseNotifier); ok {
closeNotify := x.CloseNotify()
go func() {
select {
case <-x.CloseNotify():
case <-closeNotify:
cancelFun()
}
}()
Expand Down

0 comments on commit 7bfa598

Please sign in to comment.