fix(core): consume fetch response body after flush#3516
Merged
marandaneto merged 3 commits intomainfrom May 4, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
Author
|
cc @KuaaMU |
Member
Author
|
clone from #3508 |
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
packages/core/src/__tests__/posthog.flush.spec.ts:52-83
**Prefer parameterised tests per team convention**
The two new tests share identical mock setup, `capture`, `useRealTimers`, and `flush` boilerplate. Per the team's simplicity rules ("We always prefer parameterised tests"), these could be collapsed into a single `it.each` table that varies the `body` value and the optional `cancel` assertion:
```ts
it.each([
['with ReadableStream body', { cancel: jest.fn().mockResolvedValue(undefined) }, true],
['with null body', null, false],
])('consumes response body after flush (%s)', async (_label, body, expectCancel) => {
const cancelFn = body?.cancel
mocks.fetch.mockImplementation(async () =>
Promise.resolve({ status: 200, text: () => Promise.resolve('ok'), json: () => Promise.resolve({ status: 'ok' }), body })
)
posthog.capture('test-event-1')
jest.useRealTimers()
await expect(posthog.flush()).resolves.not.toThrow()
if (expectCancel) expect(cancelFn).toHaveBeenCalledTimes(1)
})
```
### Issue 2 of 2
packages/core/src/__tests__/posthog.flush.spec.ts:231-251
**Missing null-body test for the batch flush path**
The `flush` describe block tests both the successful-cancel case and the null-body case, but this batch-flush describe block only adds the cancel test. For symmetry and complete coverage of the same runtime guard, a null-body variant (mirroring `'handles null response body gracefully after flush'`) should be added here too.
Reviews (1): Last reviewed commit: "fix(core): consume fetch response body a..." | Re-trigger Greptile |
Contributor
Contributor
|
Size Change: +308 B (0%) Total Size: 7.11 MB
ℹ️ View Unchanged
|
dustinbyrne
approved these changes
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Cloudflare Workers can warn when fetch response bodies are left unconsumed after flushing PostHog events.
Closes #3173
Changes
response.body?.cancel()after both regular and batched flushes.@posthog/coreandposthog-node.Release info Sub-libraries affected
Libraries affected
@posthog/coreis affected, but is not listed in the checklist above.Checklist
If releasing new changes
pnpm changesetto generate a changeset file