-
Notifications
You must be signed in to change notification settings - Fork 66
Add support for setting per-attempt-timeout #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@developerkunal not sure what the process to request a review is, so sorry for @-ing you |
Hi @pete-woods, Thank you for your contribution! I’ll take a look — I think this is a great addition. I just need to review the approach, and if everything looks good, I’ll approve and merge it. |
I just realised this won't work as the client is in an internal namespace. Okay, revised it slightly so it will work. |
2bedcd9
to
ec46c8a
Compare
Hi @developerkunal! Did you get a chance to have a look over my approach here? Thanks! |
func WithRetryStrategy(retryStrategy RetryStrategy) Option { | ||
return func(a *Authentication) { | ||
a.retryStrategy = client.RetryOptions(retryStrategy) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pete-woods ,
Could we update the field mapping in both management and authentication?
func WithRetryStrategy(retryStrategy RetryStrategy) Option { | |
return func(a *Authentication) { | |
a.retryStrategy = client.RetryOptions(retryStrategy) | |
} | |
} | |
func WithRetryStrategy(retryStrategy RetryStrategy) Option { | |
return func(a *Authentication) { | |
a.retryStrategy = client.RetryOptions{ | |
MaxRetries: retryStrategy.MaxRetries, | |
Statuses: retryStrategy.Statuses, | |
PerAttemptTimeout: retryStrategy.PerAttemptTimeout, | |
} | |
} | |
} |
Reasoning:
Explicit field mapping is safer and clearer. It properly handles the fact that authentication.RetryStrategy
and internal/client.RetryOptions
are distinct types, and avoids relying on direct type casting (client.RetryOptions(retryStrategy)
), which can be unsafe or misleading when structs evolve independently.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to do this, but I actually disagree in this case. If you add extra fields to the client struct, you actually want this code to fail to compile, and be prompted to add the extra fields to the public API.
If I do what you propose, when new fields are added to the client struct, this code will continue to compile and you might not notice that it's impossible to set the new fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the thoughtful reply—that’s a valid perspective, and I agree that compile-time breakage can be a useful signal during development.
That said, since this SDK is public-facing and intended for broader community use, I lean toward explicit field mapping for a few reasons:
- It makes the coupling between public and internal types more intentional.
- It improves clarity for contributors unfamiliar with internal implementation details.
- It prevents silent behavioral changes if internal structs evolve with semantics not meant for external exposure.
- It opens the door to validation, defaulting, or transformation logic between layers (if needed later).
Even though it means we might miss a compile-time nudge when fields are added, I think the tradeoff is worth it in an open-source SDK where clarity and safety are priorities.
Let’s move forward with the explicit mapping—thanks again for the great discussion and your contributions!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
e5a11e1
to
5fda310
Compare
@developerkunal Good morning! Are there any other things you'd like me to revise? Thanks! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #539 +/- ##
=======================================
Coverage 95.84% 95.84%
=======================================
Files 60 60
Lines 11683 11702 +19
=======================================
+ Hits 11197 11216 +19
Misses 366 366
Partials 120 120 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hi @pete-woods, Could you please run Thanks! |
Absolutely - will sort that right away |
edb0f1e
to
befb538
Compare
@developerkunal that's done now :) |
f930a70
to
8c47344
Compare
@developerkunal sorry to nag, would be really great to get this merged if there's no other issues |
@pete-woods Hello 👋 Thank you :) |
Hey @pete-woods @developerkunal Can you help with verifying the commit? Good to merge post that. |
- At the moment, only "complete" requests can be retried (that result in an HTTP status).
009adab
to
5a61a2e
Compare
🔧 Changes
PerAttemptTimeout
field inRetryStrategy
to prevent hanging requests.📚 References
PerAttemptTimeout
mitigates this by bounding the time spent per retry attempt.Strategy Usage Example
✅ Retry Strategy Examples
Authentication Client
Management Client
📌 Key Considerations
MaxRetries
,Statuses
, andPerAttemptTimeout
per use case.WithNoRetries()
to disable retrying.WithRetries(...)
remains functional for simpler needs.🔬 Testing
PerAttemptTimeout
logic.📝 Checklist