Skip to content

fix: invoke end callback when no chunk is passed - #32

Merged
pi0 merged 1 commit into
unjs:mainfrom
danielroe:fix/end-callback
Jul 28, 2026
Merged

fix: invoke end callback when no chunk is passed#32
pi0 merged 1 commit into
unjs:mainfrom
danielroe:fix/end-callback

Conversation

@danielroe

@danielroe danielroe commented Jul 28, 2026

Copy link
Copy Markdown
Member

reproducible in nuxt/image#2094

the ServerResponse never invokes cb when called without a chunk: the callback is detected, the write branch is skipped, writableEnded/writableFinished are set and close/finish emitted, but the promise never settles.

const ipx = createIPX({ storage: ipxFSStorage({ dir: 'some/dir' }) })
await fetchNodeRequestHandler(createIPXNodeHandler(ipx), '/s_300x300/images/colors.jpg') // hangs

this PR calls the callback after finish is emitted, and stops forwarding it to write() so it still fires exactly once (and after finish) when a chunk was passed.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected response completion callback timing so callbacks run after the response has finished closing.
    • Ensured callbacks are invoked exactly once, including when ending a response with data, an encoding, or after it has already ended.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6d3ac68f-0339-43ea-b845-9e5776a495af

📥 Commits

Reviewing files that changed from the base of the PR and between ac5ac4d and 590c1cc.

📒 Files selected for processing (2)
  • src/stream/writable.ts
  • test/index.test.ts

📝 Walkthrough

Walkthrough

Changes

Writable end callback behavior

Layer / File(s) Summary
Callback ordering and validation
src/stream/writable.ts, test/index.test.ts
Writable.end invokes its callback after the close and finish events. Tests cover calls with no chunk, chunk data, explicit encoding, and already-ended responses, including single invocation.Estimated code review effort: 2 (Simple) | ~10 minutes
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: calling end callbacks when no chunk is provided.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pi0
pi0 merged commit 5280a8b into unjs:main Jul 28, 2026
2 of 3 checks passed
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.31%. Comparing base (ac5ac4d) to head (590c1cc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #32      +/-   ##
==========================================
+ Coverage   51.34%   52.31%   +0.96%     
==========================================
  Files          10       10              
  Lines         409      411       +2     
  Branches       61       62       +1     
==========================================
+ Hits          210      215       +5     
+ Misses        186      184       -2     
+ Partials       13       12       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants