Repository navigation
Conversation
z-dule
approved these changes
Nov 11, 2026
z-dule
left a comment
There was a problem hiding this comment.
This looks like it would work, but having nested labels inside an else is terrible practice!
ur_addr_map_get ran without rate_limit_main_mutex, concurrently with inserts and with the pruning that frees entries. Hold the lock from the lookup until the entry is no longer used, new entries included. Port of #29, which unlocked twice on one path and not at all on another.
bsinou
force-pushed
the
WPB-15070-ratelimit-lock-dev
branch
from
November 11, 2026 12:11
751db75 to
179a8e3
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of #29 to
dev, rewritten.Issue
In
ratelimit_is_address_limited,ur_addr_map_getruns withoutrate_limit_main_mutex, concurrently with inserts from other threads and with the pruning, which frees entries (addr_list_foreach_del_condition). A thread can read the map while it changes, or use an entry that was just freed.Change
Take
rate_limit_main_mutexbefore the lookup and hold it until the entry is no longer used: on the existing-entry paths it is released after the entry mutex, and the new-entry path reuses it for the insert instead of locking again. Lock order is main, then entry, then allowlist, and nothing takes them in another order.#29 could not be ported as is: it unlocked right after the lookup (the entry could still be freed), unlocked a second time on the rate-limited path, and never unlocked when the address was new, which deadlocks on the first 401 from a new IP.
Testing
Built on Ubuntu 24.04 as in CI:
make checkpasses, and the TCP, TLS, UDP and DTLS client tests pass.The "rate limit by IP" client test reports FAIL on
devas well, without failing the job: it relies on the default limit of 1000 401 responses per window, which the test never reaches, andexit $?afterecho FAILexits 0. I ran the server by hand with--401-req-limit=3instead: valid credentials are served, the address is rate limited after 3 responses, and the server stays responsive, the same as ondev.