Skip to content

Commit

Permalink
Add recover() to H2 server's flushWriter.Write()
Browse files Browse the repository at this point in the history
Fixes #1748
  • Loading branch information
RPRX authored Mar 8, 2023
1 parent 4a0b45d commit 836e84b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions transport/internet/http/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ type WaitReadCloser struct {
func (w *WaitReadCloser) Set(rc io.ReadCloser) {
w.ReadCloser = rc
defer func() {
if err := recover(); err != nil {
if recover() != nil {
rc.Close()
}
}()
Expand All @@ -225,10 +225,8 @@ func (w *WaitReadCloser) Close() error {
return w.ReadCloser.Close()
}
defer func() {
if err := recover(); err != nil {
if w.ReadCloser != nil {
w.ReadCloser.Close()
}
if recover() != nil && w.ReadCloser != nil {
w.ReadCloser.Close()
}
}()
close(w.Wait)
Expand Down
7 changes: 7 additions & 0 deletions transport/internet/http/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func (fw flushWriter) Write(p []byte) (n int, err error) {
return 0, io.ErrClosedPipe
}

defer func() {
if recover() != nil {
fw.d.Close()
err = io.ErrClosedPipe
}
}()

n, err = fw.w.Write(p)
if f, ok := fw.w.(http.Flusher); ok && err == nil {
f.Flush()
Expand Down

0 comments on commit 836e84b

Please sign in to comment.