Skip to content

Commit

Permalink
Added backoff time
Browse files Browse the repository at this point in the history
  • Loading branch information
michelvocks committed Jan 22, 2020
1 parent 5dc76b5 commit 53fbaf3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugins/database/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func (m *MongoDB) RotateRootCredentials(ctx context.Context, statements []string
// runCommandWithRetry runs a command with retry.
func runCommandWithRetry(ctx context.Context, client *mongo.Client, db string, cmd interface{}) error {
timeout := time.Now().Add(1 * time.Minute)
backoffTime := 3
for {
// Run command
result := client.Database(db).RunCommand(ctx, cmd, nil)
Expand All @@ -243,7 +244,8 @@ func runCommandWithRetry(ctx context.Context, client *mongo.Client, db string, c
if time.Now().After(timeout) {
return result.Err()
}
time.Sleep(30 * time.Millisecond)
time.Sleep(time.Duration(backoffTime) * time.Second)
backoffTime += backoffTime
}
return nil
}

0 comments on commit 53fbaf3

Please sign in to comment.