Add structured logging and better error handling
This commit is contained in:
1 parent
db4e3c9611
commit
68c7dd76f2
31 files changed
+640
-109
No files matched your search
@@ -68,11 +68,26 @@ func (worker *segmentWorker) record(count int64) error {
|
||||
|
||||
func (worker *segmentWorker) reconnect(ctx context.Context, cause error) (*http.Response, error) {
|
||||
progress := worker.session.request.Progress
|
||||
logger := worker.session.request.logger().With("part_start", worker.segment.start)
|
||||
for {
|
||||
worker.failedAttempts++
|
||||
if ctx.Err() != nil || !isRetryable(cause) || worker.failedAttempts > maxRetriesWithoutProgress {
|
||||
if ctx.Err() != nil {
|
||||
return nil, cause
|
||||
}
|
||||
if !isRetryable(cause) {
|
||||
logger.Debug("error cannot be retried", "error", cause)
|
||||
return nil, cause
|
||||
}
|
||||
if worker.failedAttempts > maxRetriesWithoutProgress {
|
||||
logger.Error("giving up after repeated connection failures", "attempts", maxRetriesWithoutProgress, "error", cause)
|
||||
return nil, fmt.Errorf("gave up after %d reconnect attempts: %w", maxRetriesWithoutProgress, cause)
|
||||
}
|
||||
|
||||
logger.Warn("connection lost, reconnecting",
|
||||
"attempt", worker.failedAttempts,
|
||||
"position", worker.segment.position(),
|
||||
"error", cause,
|
||||
)
|
||||
progress.SetNotice(fmt.Sprintf("Connection lost, reconnecting (attempt %d of %d)", worker.failedAttempts, maxRetriesWithoutProgress))
|
||||
if err := waitBeforeRetry(ctx, worker.failedAttempts); err != nil {
|
||||
return nil, err
|
||||
@@ -80,6 +95,7 @@ func (worker *segmentWorker) reconnect(ctx context.Context, cause error) (*http.
|
||||
|
||||
response, err := worker.open(ctx)
|
||||
if err == nil {
|
||||
logger.Info("reconnected", "position", worker.segment.position())
|
||||
progress.SetNotice("")
|
||||
return response, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user