Move rate limiter reset to defer block (#4722)

Move `ResetLimiter()` call to defer block to ensure that it gets called even if the backup fails. Without this change, any following mailbox backups may get artificially throttled by limiter.

---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abhishek Pandey 2023-11-22 09:02:02 -08:00 committed by GitHub
parent cd55325139
commit d4519159e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -210,6 +210,12 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) {
// Select an appropriate rate limiter for the service.
ctx = op.bp.SetRateLimiter(ctx, op.Selectors.PathService(), op.Options)
// For exchange, rate limits are enforced on a mailbox level. Reset the
// rate limiter so that it doesn't accidentally throttle following mailboxes.
// This is a no-op if we are using token bucket limiter since it refreshes
// tokens on a fixed per second basis.
defer graph.ResetLimiter(ctx)
// Check if the protected resource has the service enabled in order for us
// to run a backup.
enabled, err := op.bp.IsServiceEnabled(
@ -328,12 +334,6 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) {
logger.Ctx(ctx).Infow("completed backup", "results", op.Results)
}
// For exchange, rate limits are enforced on a mailbox level. Reset the
// rate limiter so that it doesn't accidentally throttle following mailboxes.
// This is a no-op if we are using token bucket limiter since it refreshes
// tokens on a fixed per second basis.
graph.ResetLimiter(ctx)
return op.Errors.Failure()
}