-
Notifications
You must be signed in to change notification settings - Fork 4
fix: Fix TokenIssuerCache initialization semaphore #2325
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe changes update the initialization logic in the Changes
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/Digdir.Domain.Dialogporten.WebApi.Unit.Tests/TokenIssuerCacheTests.cs (1)
1-37
: Good test to verify the deadlock fix.This test effectively verifies that concurrent calls to
GetIssuerForScheme
don't cause deadlocks by creating 10 concurrent tasks and ensuring they all complete within a 1-second timeout.A few suggestions to enhance the test:
- Consider using a longer timeout (e.g., 5 seconds) to make the test more robust in CI environments or slower machines.
- You might want to add a test that verifies the actual caching functionality with real JWT schemas to ensure the cache is populated correctly.
- var completed = await Task.WhenAny(allTasks, Task.Delay(TimeSpan.FromSeconds(1))); + var completed = await Task.WhenAny(allTasks, Task.Delay(TimeSpan.FromSeconds(5)));
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/TokenIssuerCache.cs
(1 hunks)tests/Digdir.Domain.Dialogporten.WebApi.Unit.Tests/TokenIssuerCacheTests.cs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build / build-and-test
🔇 Additional comments (1)
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/TokenIssuerCache.cs (1)
53-56
: Good fix: The double-check pattern now properly releases the semaphore.The updated implementation correctly moves the second initialization check inside the
try
block, ensuring that the semaphore is always released via thefinally
block even when returning early. This prevents potential deadlocks when multiple threads attempt to initialize the cache concurrently.This implementation follows the proper double-checked locking pattern:
- First check without the semaphore (line 44) to avoid unnecessary semaphore acquisition
- Second check after acquiring the semaphore (line 53) to handle the case where another thread completed initialization between the first check and acquiring the semaphore
Summary
Testing
dotnet build tests/Digdir 8000 .Domain.Dialogporten.WebApi.Unit.Tests/Digdir.Domain.Dialogporten.WebApi.Unit.Tests.csproj -c Release --verbosity minimal
dotnet test tests/Digdir.Domain.Dialogporten.WebApi.Unit.Tests/Digdir.Domain.Dialogporten.WebApi.Unit.Tests.csproj -c Release --no-build --verbosity minimal