Skip to content

Commit

Permalink
Lower the log level for context timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
ischasny committed May 12, 2023
1 parent eac6887 commit cc5b1d3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion find.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -282,8 +283,13 @@ func (s *server) doFind(ctx context.Context, method, source string, req *url.URL
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)

if err != nil {
log.Warnw("Failed to read backend response", "err", err)
if errors.Is(err, context.Canceled) {
log.Info("Failed to read backend response because of cancelled context")
} else {
log.Warnw("Failed to read backend response", "err", err)
}
return nil, err
}

Expand Down
8 changes: 7 additions & 1 deletion find_ndjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"hash/crc32"
"io"
Expand Down Expand Up @@ -242,7 +243,12 @@ func (s *server) doFindNDJson(ctx context.Context, w http.ResponseWriter, source
continue
}
if err := scanner.Err(); err != nil {
log.Warnw("Failed to read backend response", "err", err)
if errors.Is(err, context.Canceled) {
log.Info("Failed to read backend response because of cancelled context")
} else {
log.Warnw("Failed to read backend response", "err", err)
}

return nil, circuitbreaker.MarkAsSuccess(err)
}
return nil, nil
Expand Down
7 changes: 6 additions & 1 deletion scatter_gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"sync"
"time"
)
Expand Down Expand Up @@ -41,7 +42,11 @@ func (sg *scatterGather[B, R]) scatter(ctx context.Context, forEach func(context
err = target.CB().Done(cctx, err)
}
if err != nil {
log.Errorw("failed to scatter on target", "target", target.URL().Host, "err", err, "maxWait", sg.maxWait)
if errors.Is(err, context.DeadlineExceeded) {
log.Infow("failed to scatter on target because context deadline exceeded", "target", target.URL().Host, "maxWait", sg.maxWait)
} else {
log.Errorw("failed to scatter on target", "target", target.URL().Host, "err", err, "maxWait", sg.maxWait)
}
return
}
if sout != nil {
Expand Down

0 comments on commit cc5b1d3

Please sign in to comment.