Skip to content

refactor(limits): return release handle after acquire token - #867

Open
linsein wants to merge 1 commit into
foxcpp:masterfrom
linsein:x-rate-limiter
Open

linsein wants to merge 1 commit into
foxcpp:masterfrom
linsein:x-rate-limiter

Conversation

@linsein

@linsein linsein commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

resolve: #440

@linsein

linsein commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

This PR may also resolves a potential goroutine leak.
The original rate limiter implementation requires calling Close to stop its internal goroutine.
Some modules (e.g., endpoint/smtp) don't close the limiter on stop, causing a goroutine leak on reload.

golang/x/time/rate does not depend on goroutine.

@foxcpp

foxcpp commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Overall looks good. Having limiter.Take return Handle that needs to be Release'd works for me, that would make it harder to forget Release - and that is something that happened multiple times (#546, #322 ).

@foxcpp foxcpp moved this from First Feedback Needed to Changes Needed in Maddy Mail Server PR Review Nov 26, 2026
@linsein
linsein marked this pull request as draft November 26, 2026 09:40
@linsein
linsein force-pushed the x-rate-limiter branch 2 times, most recently from 337da72 to 561ac8c Compare November 27, 2026 06:32
@linsein
linsein marked this pull request as ready for review November 27, 2026 07:26
@linsein linsein changed the title Reimplement rate limiter and concurrency limiter using golang.org/x libraries refactor(limits): return release handle after acquire token Nov 27, 2026
@foxcpp foxcpp moved this from Changes Needed to Awaiting Feedback in Maddy Mail Server PR Review Nov 27, 2026
@linsein

linsein commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Should I reopen the PR to merge into the dev branch?

@foxcpp

foxcpp commented Nov 27, 2026

Copy link
Copy Markdown
Owner

No need, refactors that have no user-facing changes are acceptable on master branch.

@linsein

linsein commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Sorry, fixed log format and lint issues in limits test suites.

@foxcpp
foxcpp self-requested a review November 27, 2026 19:51
@linsein

linsein commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

At first glance, the TestSourceOnlyLimitDoesNotPanicWhenBucketSetIsFull test fails because I changed the error status when the bucket set limiter is full—from 554 (permanent failure) to 451 (temporary failure).

I believe that classifying it as a temporary failure is more appropriate.

I am currently preparing for my vacation. I will fix it next Tuesday.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting Feedback

Development

Successfully merging this pull request may close these issues.

Replace home-made token bucket implementation with golang.org/x/time/rate

2 participants