Skip to content

Commit

Permalink
Avoid http writer panic on broken pipe (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed Mar 29, 2024
1 parent 5e8a89a commit a54f132
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion response/gzip/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"bufio"
"compress/flate"
"compress/gzip"
"errors"
"fmt"
"io"
"net"
"net/http"
"strings"
"sync"
"syscall"

gz "github.com/swaggest/rest/gzip"
)
Expand All @@ -30,7 +32,7 @@ func Middleware(next http.Handler) http.Handler {
if closer, ok := w.(io.Closer); ok {
defer func() {
err := closer.Close()
if err != nil {
if err != nil && !errors.Is(err, syscall.EPIPE) {
panic(fmt.Sprintf("BUG: cannot close gzip writer: %s", err))
}
}()
Expand Down

0 comments on commit a54f132

Please sign in to comment.