Skip to content

Comments

fix: make ServerSideSessionCleanupHost.StopAsync idempotent (cherry-pick #2345 to main)#2346

Merged
damianh merged 2 commits intomainfrom
dh/ServerSideSessionCleanupHost-main
Feb 9, 2026
Merged

fix: make ServerSideSessionCleanupHost.StopAsync idempotent (cherry-pick #2345 to main)#2346
damianh merged 2 commits intomainfrom
dh/ServerSideSessionCleanupHost-main

Conversation

@damianh
Copy link
Member

@damianh damianh commented Feb 7, 2026

Cherry-pick of #2345 to main.

Summary

  • Refactor ServerSideSessionCleanupHost to inherit from BackgroundService instead of directly implementing IHostedService
  • This makes StopAsync idempotent (safe to call multiple times without throwing)
  • Fixes issues in WebApplicationFactory<> testing scenarios where hosted services may be stopped multiple times

Changes

  • Convert to primary constructor syntax
  • Replace manual CancellationTokenSource management with BackgroundService's built-in cancellation handling
  • Simplify the while loop condition from while (true) to while (!stoppingToken.IsCancellationRequested)

References

Refactor ServerSideSessionCleanupHost to inherit from BackgroundService
instead of directly implementing IHostedService. This fixes an issue
where StopAsync throws when called multiple times without a corresponding
StartAsync call, which occurs in WebApplicationFactory testing scenarios.

Fixes: DuendeSoftware/issues#1196
Use while (!stoppingToken.IsCancellationRequested) instead of while (true)
with manual cancellation checks, removing redundant code.
@damianh damianh added the area/products/is IdentityServer label Feb 7, 2026
@damianh damianh self-assigned this Feb 7, 2026
@damianh damianh changed the title fix: make ServerSideSessionCleanupHost.StopAsync idempotent fix: make ServerSideSessionCleanupHost.StopAsync idempotent (cherry-pick #2345 to main) Feb 7, 2026
@damianh damianh requested a review from bhazen February 7, 2026 19:46
@damianh damianh merged commit 1ed766a into main Feb 9, 2026
18 of 19 checks passed
@damianh damianh deleted the dh/ServerSideSessionCleanupHost-main branch February 9, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/products/is IdentityServer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants