Flush pending events on AppDomain.ProcessExit
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- csharp
- Domain
- backend-api-design
Research direction
Start by reading the client disposal and flush paths, the terminating-exception flush added in issue #356, and the existing PostHogOptions definitions. Decide how shutdown handling should resolve the open questions about configuration, disposal, and timeout semantics, then check that process exit waits only within the configured bound and does not race with DisposeAsync; done means pending events get a best-effort flush and the handler is removed on disposal.
Written by the indexing model from the issue text.
Description
Problem
An application that never disposes the client loses the events still queued when the process exits normally. Today the only safety nets are the periodic flush and, with CaptureUnhandledExceptions, the flush after a terminating exception (#356).
Proposal
Register an AppDomain.CurrentDomain.ProcessExit handler that performs a bounded flush or disposal of the client.
- Add
PostHogOptions.ShutdownTimeoutand block for at most that long. Default 30 seconds, matching the regular shutdown default in the Node and Rust SDKs and the .NET generic host. The option was left out of #356 because there it would only have bounded the flush after a terminating exception, which stays at a fixed 2 seconds: that flush blocks a process that is already crashing. - Run the flush off the exiting thread, as the terminating-exception flush does, so it cannot deadlock on a
SynchronizationContext. - Do not dispose twice or concurrently with an explicit
DisposeAsync. - Unregister the handler when the client is disposed.
Delivery stays best-effort: an abrupt termination or a runtime failure can prevent the handler from running or completing.
Open questions
- Whether the hook is always on or behind an option.
- Whether it flushes only or fully disposes the client.
- Whether
DisposeAsyncshould also honorShutdownTimeout, so the option has one meaning everywhere. - Whether the terminating-exception flush should use
min(ShutdownTimeout, 2 seconds), so a shorter configured budget also applies to a crash.
Context
Raised as a non-blocking follow-up in the review of #356.
- Dominant language
- C#
- Stars
- 47
- Forks
- 23
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 30
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PostHog/posthog-dotnet
-
enhancement feature/error-tracking
Difficulty 5/5 Over a week Newbie friendliness 35/100
PostHog/posthog-dotnet#384 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement feature/error-tracking
Difficulty 4/5 3-5 days Newbie friendliness 45/100
PostHog/posthog-dotnet#333 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement team/llm-analytics
Difficulty 5/5 Over a week Newbie friendliness 25/100
PostHog/posthog-dotnet#224 ·
Maintainers usually reply within 1 day
-
SDK referencesOpendocumentation
Difficulty 3/5 1-2 days Newbie friendliness 45/100
PostHog/posthog-dotnet#212 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
PostHog/posthog-dotnet#210 · 2 reactions ·
Maintainers usually reply within 1 day
All issues in PostHog/posthog-dotnet
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
quality 提案 要トリアージ
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
The Language and Region lists in Options read to a screen reader as "LanguageInfo { Id = ar, ... }"Openbug localization small ui
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
hexide-io/HexIDE#4176 · 1 comment ·
Maintainers usually reply within 1 day
-
kind/chore status/draft
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Altinn/altinn-profile#1102 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MarcelRoozekrans/Rag.NET#1030 ·
Maintainers usually reply within 1 day