Skip to content

Fix fire-and-forget background task in LocalFeatureFlagsLoader - #161

Merged
haacked merged 4 commits into
mainfrom
haacked/fix-fire-and-forget
Feb 26, 2026
Merged

Fix fire-and-forget background task in LocalFeatureFlagsLoader#161
haacked merged 4 commits into
mainfrom
haacked/fix-fire-and-forget

Conversation

@haacked

@haacked haacked commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Await the polling task during disposal so in-flight API calls complete before resources are disposed, preventing ObjectDisposedException
  • Fix disposal ordering in PostHogClient.DisposeAsync() so the API client remains alive while the polling task winds down
  • Mark _pollingTask volatile for cross-thread visibility consistency
  • Use GetAwaiter().GetResult() instead of .Wait() in all sync Dispose bridges for cleaner exception stack traces
  • Add tests for graceful disposal during in-flight poll, double-dispose, and disposal before polling starts

Follows the same pattern established in AsyncBatchHandler (PR #158).

Fixes #159

Test plan

  • Existing tests pass on both net8.0 and netcoreapp3.1
  • New CompletesGracefullyDuringInFlightPoll test passes on both frameworks
  • New DoesNotDisposeTwice test passes on both frameworks
  • New CompletesGracefullyWhenPollingNeverStarted test passes on both frameworks

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LocalFeatureFlagsLoader has fire-and-forget background task pattern

3 participants