Skip to content

Fix NodeStream.toString registers duplicate error event listener - #7143

Merged
tim-smart merged 2 commits into
mainfrom
audit/repro-f0008-nodestream-duplicate-listener
Aug 8, 2026
Merged

Fix NodeStream.toString registers duplicate error event listener#7143
tim-smart merged 2 commits into
mainfrom
audit/repro-f0008-nodestream-duplicate-listener

Conversation

@fubhy

@fubhy fubhy commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

  • remove the duplicate one-shot error listener from NodeStream.toString
  • rewrite the regression test to assert the supplied stream's public listener count without monkey-patching
  • add a patch changeset for @effect/platform-node-shared

Validation

  • pnpm test --run packages/platform-node-shared/test/NodeStream.test.ts
  • pnpm --filter @effect/platform-node-shared check
  • targeted oxlint and dprint check

Closes EFF-569

@fubhy fubhy added bug Something isn't working audit Findings originating from the Effect runtime correctness audit labels Aug 7, 2026
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 411d397

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@effect/platform-node-shared Patch
effect Patch
@effect/ai-anthropic Patch
@effect/ai-openai Patch
@effect/ai-openai-compat Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/vitest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-slopcop effect-slopcop Bot added the 3.0 Used for issues, pull requests, etc. that are relevant for the `v3` branch targeting Effect v3. label Aug 7, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes
This PR fixes a duplicate error event listener registration in NodeStream.toString by removing the second stream.once("error", ...) call, matching the implementation of toArrayBuffer. It also adds a focused regression test that verifies exactly one error listener is registered.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@fubhy fubhy added 4.0 slop and removed 3.0 Used for issues, pull requests, etc. that are relevant for the `v3` branch targeting Effect v3. labels Aug 7, 2026
@fubhy
fubhy force-pushed the audit/repro-f0008-nodestream-duplicate-listener branch from f7594e3 to a27bb41 Compare August 7, 2026 16:52

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

The latest commit reverts the source fix from the prior review, so NodeStream.toString again registers two error listeners and the newly added regression test fails. Do not merge as-is.

Reviewed changes
Since the prior Pullfrog review at f7594e3, the branch was rewritten:

  • Reverted the NodeStream.ts fix; the duplicate stream.once("error", ...) registration is back.
  • Removed the .changeset/sweet-lizards-sing.md patch changeset.
  • Rewrote the regression test in NodeStream.test.ts to count error listeners on the evaluated stream instance rather than monkey-patching Readable.prototype.once.

🚨 PR title and commit message no longer match the change

The PR title and commit a27bb41 say "Fix duplicate NodeStream error listener", but packages/platform-node-shared/src/NodeStream.ts is unchanged from main and still contains two stream.once("error", ...) registrations in toString (src/NodeStream.ts:235-238). The PR body correctly describes the change as test-only, yet the commit message claims a fix. Running the reproduction command from the body confirms the test fails with expected 2 to equal 1.

To land this safely, either restore the implementation fix (remove the duplicate listener and re-add a patch changeset) or align the title/commit with the test-only intent and do not merge until a separate fix is in place.

Technical details
# Reverted fix and failing regression test

## Affected sites
- `packages/platform-node-shared/src/NodeStream.ts:235-238``toString` registers `error` twice (pre-existing bug, unchanged by this PR).
- `packages/platform-node-shared/test/NodeStream.test.ts:174-191` — new regression test asserts exactly one `error` listener; it fails because the source still registers two.
- `.changeset/sweet-lizards-sing.md` — removed in the latest commit.

## Required outcome
- The duplicate `stream.once("error", ...)` registration must be removed before this PR can pass CI.
- If this PR is meant to be test-only, the title and commit message must not claim a fix, and the branch should not be merged while CI is red.

## Suggested approach
- Remove the second `stream.once("error", ...)` block in `toString` so the implementation matches `toArrayBuffer`.
- Re-add a patch changeset for `@effect/platform-node-shared`.
- Keep the improved regression test, which is more isolated than the `Readable.prototype.once` version reviewed previously.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix it ➔View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@tim-smart
tim-smart enabled auto-merge (squash) August 8, 2026 08:45
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.92 KB 6.92 KB 0.00 KB (0.00%)
batching.ts 9.72 KB 9.72 KB 0.00 KB (0.00%)
brand.ts 6.60 KB 6.60 KB 0.00 KB (0.00%)
cache.ts 10.59 KB 10.59 KB 0.00 KB (0.00%)
config.ts 20.91 KB 20.91 KB 0.00 KB (0.00%)
differ.ts 19.77 KB 19.77 KB 0.00 KB (0.00%)
http-client.ts 21.52 KB 21.52 KB 0.00 KB (0.00%)
logger.ts 10.81 KB 10.81 KB 0.00 KB (0.00%)
metric.ts 8.86 KB 8.86 KB 0.00 KB (0.00%)
optic.ts 6.68 KB 6.68 KB 0.00 KB (0.00%)
pubsub.ts 14.86 KB 14.86 KB 0.00 KB (0.00%)
queue.ts 11.54 KB 11.54 KB 0.00 KB (0.00%)
schedule.ts 10.71 KB 10.71 KB 0.00 KB (0.00%)
schema-class.ts 19.48 KB 19.48 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.36 KB 29.36 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.63 KB 25.63 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.55 KB 13.55 KB 0.00 KB (0.00%)
schema-string.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.38 KB 15.38 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 21.52 KB 21.52 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.00 KB 24.00 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.74 KB 18.74 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.57 KB 18.57 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.43 KB 18.43 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.59 KB 22.59 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.08 KB 19.08 KB 0.00 KB (0.00%)
schema.ts 18.73 KB 18.73 KB 0.00 KB (0.00%)
stm.ts 12.59 KB 12.59 KB 0.00 KB (0.00%)
stream.ts 9.67 KB 9.67 KB 0.00 KB (0.00%)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes
Since the prior Pullfrog review at a27bb41, the branch now restores the implementation fix and aligns with the PR title:

  • Restored the NodeStream.toString fix, removing the duplicate stream.once("error", ...) registration so toString now registers a single error listener, consistent with toArrayBuffer.
  • Re-added the .changeset/sweet-lizards-sing.md patch changeset for @effect/platform-node-shared.
  • Rewrote the regression test to assert stream.listenerCount("error") === 1 on the evaluated stream after a fork + yield, replacing the stream.once monkey-patch with a cleaner count-based check.

Verified locally: the fixed source passes the new test (15/15 runs), and reintroducing the duplicate listener makes it fail with expected 2 to equal 1 — so the test is discriminating, not theatre.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@tim-smart
tim-smart merged commit 089313e into main Aug 8, 2026
18 of 19 checks passed
@tim-smart
tim-smart deleted the audit/repro-f0008-nodestream-duplicate-listener branch August 8, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 audit Findings originating from the Effect runtime correctness audit bug Something isn't working slop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants