Skip to content

fix(RateLimitRoundtripper): Fix mutex leak and not respecting context cancellation#2298

Merged
stevehipwell merged 1 commit intointegrations:mainfrom
pete-woods:fix-rate-limit-roudtrip-issues
Dec 20, 2025
Merged

fix(RateLimitRoundtripper): Fix mutex leak and not respecting context cancellation#2298
stevehipwell merged 1 commit intointegrations:mainfrom
pete-woods:fix-rate-limit-roudtrip-issues

Conversation

@pete-woods
Copy link
Copy Markdown
Contributor

@pete-woods pete-woods commented Jun 26, 2024

Resolves #2299

  • Make sure that all exit paths from functions correctly release the mutex.
  • Add a sleep function that respects context cancellation, and use it in-place of time.Sleep.

Before the change?

  • Cancellation is not being respected in the transport's sleeps.
  • Additionally, there's a path out of the function that does not unlock the mutex.

After the change?

  • Cancellation is now respected, and the mutex always unlocks.

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@pete-woods pete-woods changed the title RateLimitRoundtripper: Fix mutex leak and not respecting context cancellation fix(RateLimitRoundtripper): Fix mutex leak and not respecting context cancellation Jun 26, 2024
@pete-woods pete-woods marked this pull request as ready for review June 26, 2024 14:30
@pete-woods pete-woods force-pushed the fix-rate-limit-roudtrip-issues branch from 636a4db to 2795869 Compare September 3, 2024 11:19
@pete-woods pete-woods force-pushed the fix-rate-limit-roudtrip-issues branch from 2795869 to 217adae Compare February 28, 2025 08:45
@pete-woods pete-woods force-pushed the fix-rate-limit-roudtrip-issues branch from 217adae to a6a9f0d Compare August 8, 2025 10:30
@deiga
Copy link
Copy Markdown
Collaborator

deiga commented Nov 28, 2025

Hey @pete-woods 👋

Thanks for the contribution!

Would you be available to resolve the merge conflict?

Would it also be possible to explain in more detail how the changes work?
I'm not a golang expert and for such a project having more descriptive code/comments is just a good practice ☺️

@pete-woods
Copy link
Copy Markdown
Contributor Author

Absolutely - I'll rebase when I get a moment

@pete-woods pete-woods force-pushed the fix-rate-limit-roudtrip-issues branch from a6a9f0d to ce27887 Compare November 28, 2025 22:03
@github-actions github-actions bot added the Type: Bug Something isn't working as documented label Nov 28, 2025
@pete-woods
Copy link
Copy Markdown
Contributor Author

Okay, rebased and resolved the conflict now

@pete-woods pete-woods force-pushed the fix-rate-limit-roudtrip-issues branch from ce27887 to 40a8d48 Compare November 29, 2025 20:36
@pete-woods
Copy link
Copy Markdown
Contributor Author

@nickfloyd sorry for direct @ - is there any chance you have time to look at this PR that tries to fix a deadlock/cancellation issue? (You're the #1 contributor to the repo)

@deiga
Copy link
Copy Markdown
Collaborator

deiga commented Nov 30, 2025

@pete-woods It's Thanksgiving, so most US-based folks won't be around. We've raised this PR as something to look at next week :)

@nickfloyd nickfloyd moved this from Backlog to On Deck in Terraform Provider Dec 1, 2025
@nickfloyd nickfloyd added this to the v7 Next milestone Dec 1, 2025
@pete-woods pete-woods force-pushed the fix-rate-limit-roudtrip-issues branch 4 times, most recently from d20eee6 to 4cb9825 Compare December 8, 2025 15:15
@stevehipwell
Copy link
Copy Markdown
Collaborator

@pete-woods could you please rebase and I'll see if we can get it merged.

@pete-woods pete-woods force-pushed the fix-rate-limit-roudtrip-issues branch from 4cb9825 to d9c33b1 Compare December 9, 2025 20:59
@pete-woods
Copy link
Copy Markdown
Contributor Author

@pete-woods could you please rebase and I'll see if we can get it merged.

Done

@pete-woods pete-woods force-pushed the fix-rate-limit-roudtrip-issues branch from d9c33b1 to 0d7ec81 Compare December 10, 2025 15:58
…ellation

- Make sure that all exit paths from functions correctly release the mutex.
- Add a sleep function that respects context cancellation, and use it in-place of time.Sleep.
@pete-woods pete-woods force-pushed the fix-rate-limit-roudtrip-issues branch from 0d7ec81 to d612fae Compare December 10, 2025 15:58
Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @pete-woods.

FYI I'm not sure this is going to have much of an immediate impact given the general lack usage of the context based provider methods (most call to the client use context.Background()). That said it will provide a noticeable benefit to resources where we adopt the context based patterns.

LGTM

@stevehipwell stevehipwell modified the milestones: v7 Next, v6.9.1 Patch Dec 10, 2025
@pete-woods
Copy link
Copy Markdown
Contributor Author

Thanks for this PR @pete-woods.

FYI I'm not sure this is going to have much of an immediate impact given the general lack usage of the context based provider methods (most call to the client use context.Background()). That said it will provide a noticeable benefit to resources where we adopt the context based patterns.

LGTM

It's been quite some time since I made this PR, but some brain cells are telling me it was getting stuck in the sleep between retries, at least as best as I can remember.

@stevehipwell
Copy link
Copy Markdown
Collaborator

@pete-woods yes it does, but I suspect that it will still do so in most cases as there is no context in the legacy methods to propagate down. Your fix looks a lot like the pattern in the library I use when writing GitHub apps, which coincidentally is where I'd like to move this implementation. I think we'll also need to look at the default context timeout and add provider scoped timeout configuration for retries as the default is 20 mins.

@stevehipwell stevehipwell merged commit 9fc330c into integrations:main Dec 20, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from 🔥 Backlog to ✅ Done in 🧰 Octokit Active Dec 20, 2025
@github-project-automation github-project-automation bot moved this from On Deck to Done in Terraform Provider Dec 20, 2025
@pete-woods pete-woods deleted the fix-rate-limit-roudtrip-issues branch January 5, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented

Projects

Development

Successfully merging this pull request may close these issues.

[BUG]: Cancelling terraform apply hangs indefinitely

4 participants