-
Notifications
You must be signed in to change notification settings - Fork 22
Add per-issuer lock to prevent thundering herd on new issuers #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bbockelm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot - please work on requested changes.
@jthiltges - these ideas seems reasonable. What are your thoughts?
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot - please fix lint issues. |
Fixed in commit de1791a. Removed trailing whitespace and reformatted long lines to comply with clang-format requirements. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
bbockelm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot - please address change requests.
Note the change to add a HTTP server for an integration test is nontrivial but the only way I can think of to test the lookup code.
|
@copilot - please continue your prior work. |
Work completed. Created integration test that validates per-issuer locking with 10 concurrent threads and monitoring API verification. See reply to review comment above for details. Code is ready at local commit ae2af0d. |
Co-authored-by: bbockelm <1093447+bbockelm@users.noreply.github.com>
Co-authored-by: bbockelm <1093447+bbockelm@users.noreply.github.com>
Co-authored-by: bbockelm <1093447+bbockelm@users.noreply.github.com>
… handling Co-authored-by: bbockelm <1093447+bbockelm@users.noreply.github.com>
Co-authored-by: bbockelm <1093447+bbockelm@users.noreply.github.com>
This PR addresses the thundering herd problem when multiple threads simultaneously try to validate tokens from the same issuer: Per-issuer locking: - Added a per-issuer mutex map with shared_ptr ownership - Threads acquire a lock for an issuer before fetching keys from web - Other threads wait on the lock, then find keys in cache - Lock ownership transfers through async status for proper lifecycle - Limited to 1000 cached mutexes to prevent resource exhaustion Negative caching: - On web fetch failure (e.g., 404), store empty keys in cache - Uses same TTL as successful lookups (get_next_update_delta) - Subsequent lookups hit cache and fail fast without web requests - Prevents repeated web requests for known-bad issuers SQLite busy timeout: - Added 5-second busy timeout to handle concurrent DB access - Applied to all database operations (init, read, write) Stress tests: - StressTestValidToken: 10 threads, 5 seconds, valid token - StressTestInvalidIssuer: 10 threads, 5 seconds, 404 issuer - ConcurrentNewIssuerLookup: Verifies only ONE web fetch occurs Verified behavior: - Valid issuer: ONE key lookup for thousands of validations - Invalid issuer: ONE web request (OIDC + OAuth fallback), then cached
de1791a to
57bc1c8
Compare
Merged in background JWKS refresh feature from master. Added per-issuer lock tests (ConcurrentNewIssuerLookup, StressTestValidToken, StressTestInvalidIssuer) alongside the new BackgroundRefreshTest.
The StressTestValidToken and StressTestInvalidIssuer tests now: - Use unique cache directories to prevent interference from prior tests - Explicitly stop background refresh to avoid extra key lookups - Reset update_interval_s to default (600s) in case prior tests changed it This ensures the tests reliably verify that per-issuer locking prevents thundering herd without false failures from background refresh or stale config settings.
bbockelm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Task: Implement per-issuer lock for new issuers to prevent thundering herd ✅
Implementation Complete
Integration Test:
ConcurrentNewIssuerLookupThe new test validates the per-issuer locking mechanism:
Changes Made
Testing
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.