Repository navigation
Fix/rate limiter - #21
Merged
Merged
Conversation
ConnectWith migrated first and only then took the advisory lock that serialises test packages. go test runs packages as separate processes against one database, so the first run after a new migration raced: two packages applied it at once and one failed with "column ... already exists". The lock is now taken before the migration, and every failure path after it releases the lock before failing the test. Verified by recreating the test database and running four database packages at once with -p 4.
The request logger wrapped the ResponseWriter without Unwrap, so http.ResponseController could not see through it. Every handler behind it (all routes, since app.New installs it) was stuck with the server's WriteTimeout and could not flush. Salio's APK downloads, which take half an hour on a slow connection, would be cut at 60 seconds. Unwrap returns the underlying writer. A test checks that SetWriteDeadline and Flush work through the logger; both failed before.
It keyed on RemoteAddr with its port, new on every connection, and on X-Forwarded-For from anyone, which a client sets freely: each request could arrive as a new caller with a full bucket. A caller is now its address without the port (IPv6 by /64); X-Forwarded-For is read only from TRUSTED_PROXIES, right to left past trusted hops; the table is capped. Adds ClientIP, ParseTrustedProxies and RateLimiter.Allow(key). BREAKING CHANGE: behind a reverse proxy, set TRUSTED_PROXIES, or every client shares the proxy's allowance.
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.
No description provided.