Skip to content

Commit ffc6158

Browse files
authored
If frontend copy body return error, log it (#4533)
* if frontend copy body return error, log it Signed-off-by: Mengmeng Yang <[email protected]>
1 parent 86d5f52 commit ffc6158

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/frontend/transport/handler.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package transport
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"flag"
78
"fmt"
89
"io"
@@ -11,6 +12,7 @@ import (
1112
"net/url"
1213
"strconv"
1314
"strings"
15+
"syscall"
1416
"time"
1517

1618
"github.com/go-kit/log"
@@ -143,8 +145,11 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
143145
}
144146

145147
w.WriteHeader(resp.StatusCode)
146-
// we don't check for copy error as there is no much we can do at this point
147-
_, _ = io.Copy(w, resp.Body)
148+
// log copy response body error so that we will know even though success response code returned
149+
bytesCopied, err := io.Copy(w, resp.Body)
150+
if err != nil && !errors.Is(err, syscall.EPIPE) {
151+
level.Error(util_log.WithContext(r.Context(), f.log)).Log("msg", "write response body error", "bytesCopied", bytesCopied, "err", err)
152+
}
148153

149154
// Check whether we should parse the query string.
150155
shouldReportSlowQuery := f.cfg.LogQueriesLongerThan != 0 && queryResponseTime > f.cfg.LogQueriesLongerThan

0 commit comments

Comments
 (0)