Skip to content

feat: add MaxRetries and MaxSleep options to customize retry behavior - #160

Closed
AdamMagued wants to merge 1 commit into
uber-go:masterfrom
AdamMagued:feat-configurable-retries-and-sleep
Closed

AdamMagued wants to merge 1 commit into
uber-go:masterfrom
AdamMagued:feat-configurable-retries-and-sleep

Conversation

@AdamMagued

Copy link
Copy Markdown

Description

This change introduces MaxRetries and MaxSleep functional options to allow callers to configure retry behavior when checking for goroutine leaks in Find, VerifyNone, and VerifyTestMain.

Previously, the maximum number of retry attempts (_defaultRetries = 20) and maximum sleep interval (100 * time.Millisecond) were hardcoded in buildOpts. Callers could not adjust these parameters for scenarios where goroutines require additional time to terminate, nor could they disable retries completely (e.g., via MaxRetries(0)) when testing code that must not leak goroutines even transiently.

Changes

  • Added MaxRetries(n int) Option to customize the maximum number of retry attempts (defaulting to 20). Setting MaxRetries(0) terminates after the initial inspection without retrying.
  • Added MaxSleep(d time.Duration) Option to customize the maximum exponential backoff sleep duration between retry attempts (defaulting to 100ms).
  • Exported MaxSleep while preserving internal maxSleep compatibility.
  • Added safety bounding in opts.retry before evaluating bit shifts to prevent integer overflow when large retry counts are configured.
  • Added test coverage in options_test.go and leaks_test.go verifying that MaxRetries and MaxSleep configure option values, control retry termination, and adjust backoff timings.

Fixes #93

Add MaxRetries and MaxSleep functional options to configure the retry
attempts and maximum exponential backoff sleep duration when searching
for leaked goroutines in Find, VerifyNone, and VerifyTestMain.

Fixes uber-go#93
@AdamMagued

Copy link
Copy Markdown
Author

Closing to align with previous maintainer direction on RetryPolicy abstraction.

@AdamMagued AdamMagued closed this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make maxRetries and maxSleep configurable in goleak

1 participant