Skip to content

Split public and internal drainStream and cover with tests#582

Draft
Copilot wants to merge 14 commits intomainfrom
copilot/sub-pr-578
Draft

Split public and internal drainStream and cover with tests#582
Copilot wants to merge 14 commits intomainfrom
copilot/sub-pr-578

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 26, 2026

drainStream previously hung when the server closed the connection before emitting end, and had no coverage for terminal stream states (already errored/ended/closed) that create race conditions if encountered before listeners are attached.

Changes

  • stream.ts: Split into two functions:
    • drainStream(stream) — simplified public API (no context), exported from package entrypoint; adds early-exit guards for errored, readableEnded, and closed states; resolves on close event to handle server-side connection teardown before end
    • drainStreamInternal(ctx, stream) — internal variant used by node_base_connection.ts; same logic plus TRACE-level logging of chunk counts, byte totals, and drain duration
  • node_base_connection.ts: Switched all call sites from drainStream to drainStreamInternal
  • node_stream.test.ts / node_stream_internal.test.ts: New unit test suites covering normal end, already-ended, already-errored, live error, thrown error, and already-closed stream states for both functions

Checklist


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Split public and internal drainStream functions and cover with tests Split public and internal drainStream and cover with tests Feb 26, 2026
@peter-leonov-ch peter-leonov-ch force-pushed the always_drain_stream_2 branch from 6e90efb to b976d08 Compare March 2, 2026 12:53
Base automatically changed from always_drain_stream_2 to main March 2, 2026 12:59
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.

3 participants