Skip to content

Comments

fix: make ServerSideSessionCleanupHost.StopAsync idempotent#2345

Merged
damianh merged 2 commits intoreleases/is/7.4.xfrom
dh/ServerSideSessionCleanupHost
Feb 9, 2026
Merged

fix: make ServerSideSessionCleanupHost.StopAsync idempotent#2345
damianh merged 2 commits intoreleases/is/7.4.xfrom
dh/ServerSideSessionCleanupHost

Conversation

@damianh
Copy link
Member

@damianh damianh commented Feb 7, 2026

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

@damianh damianh added this to the is-7.4.6 milestone Feb 7, 2026
@damianh damianh changed the base branch from main to releases/is/7.4.x February 7, 2026 19:24
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 merged commit 27d0d4a into releases/is/7.4.x Feb 9, 2026
15 of 17 checks passed
@damianh damianh deleted the dh/ServerSideSessionCleanupHost branch February 9, 2026 15:15
damianh added a commit that referenced this pull request Feb 9, 2026
…nupHost-main

fix: make ServerSideSessionCleanupHost.StopAsync idempotent (cherry-pick #2345 to main)
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