Repository navigation
Conversation
PostHog writes and reads each queued event on its own queue thread, and close() neither waits for that thread nor stops it. stop() could delete the storage while the thread still held an event file open. Linux unlinks an open file, but Windows refuses to delete it, so io.put.analytics outlived an opt-out there (#723). The SDK routes every queue file stream through the encryption hook, so a pass-through PostHogEncryption now tracks open streams. stop() waits for each event the SDK accepted to open its file, then closes every open stream and refuses new ones before deleting. The SDK already treats a failed stream as a dropped record and deletes the file itself. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4125e3863f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| lock.withLock { open -= outputStream } | ||
| super.close() |
There was a problem hiding this comment.
Keep stream removal synchronized with the underlying close
On Windows, stopping while the queue thread closes a stream can still leave storage undeleted: this removes the stream from open and releases the lock before super.close() closes its file handle. If closeAll() runs in that interval, it excludes the still-open stream and returns, allowing both deletion attempts in stop() to fail before the queue thread resumes. The input-stream wrapper has the same race. Synchronize the underlying close and removal with closeAll() so an untracked open handle cannot survive its return.
Useful? React with 👍 / 👎.
The gate runs stop() and start() in one guarded step, so a throwing stop left analytics off for the new account. Failures stay with the gate's policy: PostHog never breaks a flow. client.close() can no longer skip the final delete. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Waiting for pending writes let the queue read and send events captured before an opt-out. Reads now fail from the start of stop(), so those events drop as before. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Change
Stopping analytics now deletes PostHog's storage on Windows too. Fixes #723, part of #858.
sequenceDiagram participant Q as PostHogQueueThread participant S as stop() Q->>Q: open queue/<id>.event, write S->>S: wait until each accepted event's write started (5 s cap) S->>Q: close open queue streams, refuse new ones S->>S: delete storage, close client, delete againclose()doesn't wait for its queue thread; Windows can't delete an open file.PostHogEncryptiontracks the streams.stop()stays best-effort, so the nextstart()always runs.Validation
:core:telemetrytests, detekt and lint on macOSUnverified: the 5 s cap is never hit in tests.