Skip to content

Commit

Permalink
fix: don't log unexpected EOF client issues as errors (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech authored Mar 6, 2024
1 parent 4af0386 commit 3844424
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions router/core/graphql_prehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/ecdsa"
"errors"
"fmt"
"io"
"net/http"
"strconv"
"sync"
Expand Down Expand Up @@ -165,7 +166,15 @@ func (h *PreHandler) Handler(next http.Handler) http.Handler {
body, err := h.operationProcessor.ReadBody(buf, r.Body)
if err != nil {
finalErr = err
requestLogger.Error(err.Error())

// This error is expected e.g. when the client defines (Content-Length) and aborts the request before
// It means that EOF was encountered in the middle of reading the body. This is not a server error.
if errors.Is(err, io.ErrUnexpectedEOF) {
requestLogger.Debug("unexpected EOF while reading request body", zap.Error(err))
} else {
requestLogger.Error("failed to read request body", zap.Error(err))
}

writeRequestErrors(r.Context(), http.StatusBadRequest, graphql.RequestErrorsFromError(err), w, requestLogger)
return
}
Expand Down Expand Up @@ -344,7 +353,7 @@ func (h *PreHandler) Handler(next http.Handler) http.Handler {
validatedReq, err := h.accessController.Access(w, r)
if err != nil {
finalErr = err
requestLogger.Error(err.Error())
requestLogger.Error("failed to authenticate request", zap.Error(err))

rtrace.AttachErrToSpan(authenticateSpan, err)
authenticateSpan.End()
Expand Down Expand Up @@ -449,7 +458,7 @@ func (h *PreHandler) writeOperationError(ctx context.Context, w http.ResponseWri
writeInternalError(ctx, w, requestLogger)
}
default: // If we have an unknown error, we log it and return an internal server error
requestLogger.Error(err.Error())
requestLogger.Error("unknown operation error", zap.Error(err))
writeInternalError(ctx, w, requestLogger)
}
}

0 comments on commit 3844424

Please sign in to comment.