fix: cancel per-attempt gRPC contexts promptly - #1798
Conversation
Signed-off-by: zjuzhongwen <zjuzhongwen@outlook.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 13 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Dosik13
left a comment
There was a problem hiding this comment.
Thank you for the contribution — the fix is correct, and extracting the attempt into its own function is a clean way to scope the defer cancel(). Summing up my comments:
- Add a one-line doc comment on the helper so the per-attempt scope doesn't get inlined away later.
- Deduplicate the two branches so the marshal + return appears once.
- Please move the test into the existing
mock_test.goand drive it through_Execute(BUSY→OK) — that checks the real retry behaviour and also covers thetransactionpath.
One more small thing: please change the issue reference to Fixes #1797 so it auto-closes. Happy to approve after that!
Signed-off-by: zjuzhongwen <zjuzhongwen@outlook.com>
@Dosik13 Thanks for the review! I’ve addressed all the comments:
The test verifies that the first attempt’s context is already canceled when the second attempt begins. Thanks again! |
Description:
_Executepreviously calleddefer cancel()directly inside its retry loop. Since the defer belonged to the outer function scope, cancellation for completed attempts was delayed until_Executereturned.This could keep timeout-related resources alive longer than necessary when an RPC completed before its configured deadline.
The RPC invocation is now scoped to a small closure, allowing
defer cancel()to run at the end of each attempt.Related issue(s):
Fixes #1797
Notes for reviewer:
Checklist