Suppress benign broken pipe and context closed warnings (#2927)

This commit is contained in:
DingDongSoLong4
2022-09-19 07:01:40 +02:00
committed by GitHub
parent 5e97ecd260
commit 8efbcc1c4d
11 changed files with 172 additions and 105 deletions

View File

@@ -5,11 +5,13 @@ import (
"crypto/md5"
"crypto/tls"
"encoding/base64"
"errors"
"fmt"
"io"
"net/http"
"regexp"
"strings"
"syscall"
"time"
)
@@ -127,5 +129,11 @@ func ServeImage(image []byte, w http.ResponseWriter, r *http.Request) error {
w.Header().Add("Etag", etag)
w.Header().Set("Cache-Control", "public, max-age=604800, immutable")
_, err := w.Write(image)
// Broken pipe errors are common when serving images and the remote
// connection closes the connection. Filter them out of the error
// messages, as they are benign.
if errors.Is(err, syscall.EPIPE) {
return nil
}
return err
}