Skip to content

Commit

Permalink
Conditionally set reconnectLoop error state based on context error
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrks committed Feb 5, 2025
1 parent 4ca372d commit 50ca63b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions db/active_replicator_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,26 @@ func (a *activeReplicatorCommon) reconnectLoop() {
return err != nil, err, nil
}

err, _ := base.RetryLoop(ctx, "replicator reconnect", retryFunc, sleeperFunc)
retryErr, _ := base.RetryLoop(ctx, "replicator reconnect", retryFunc, sleeperFunc)
// release timer associated with context deadline
if deadlineCancel != nil {
deadlineCancel()
}
if err != nil {
if retryErr != nil {
switch ctxErr := ctx.Err(); ctxErr {
case context.Canceled:
// replicator was stopped - appropriate state has already been set
base.InfofCtx(ctx, base.KeyReplicate, "exiting reconnect loop: %v", ctxErr)
return
case context.DeadlineExceeded:
// timeout on reconnecting state
base.WarnfCtx(ctx, "aborting reconnect loop after timeout: %v", ctxErr)
default:
// unexpected error from retry loop
base.WarnfCtx(ctx, "aborting reconnect loop after error: %v", retryErr)
}

a.replicationStats.NumReconnectsAborted.Add(1)
base.WarnfCtx(ctx, "couldn't reconnect replicator: %v", err)
a.lock.Lock()
defer a.lock.Unlock()
a.setState(ReplicationStateError)
Expand Down

0 comments on commit 50ca63b

Please # to comment.