Skip to content

fix(core): prevent late console logs from failing the run (isolate: false)#1368

Merged
fi3ework merged 1 commit into
mainfrom
fix-late-console-rpc-closed
Jun 4, 2026
Merged

fix(core): prevent late console logs from failing the run (isolate: false)#1368
fi3ework merged 1 commit into
mainfrom
fix-late-console-rpc-closed

Conversation

@fi3ework

@fi3ework fi3ework commented Jun 3, 2026

Copy link
Copy Markdown
Member

Summary

With isolate: false, all test files share one worker but each file owns its own birpc channel. The host disposes a file's channel as soon as the file finishes, while the worker only closes it when the next file starts. A console reference captured by a file (e.g. a logger that flushes from a late setTimeout/microtask) could fire in or after that window and forward the log over a disposed/closed channel.

The console interceptor does not await the forward, so the rejected send surfaced as an unhandledRejection ([birpc] rpc is closed) that failed the run even though every assertion passed, and blamed the wrong file — whichever happened to be running when the late log fired.

Console forwarding is best-effort, with two failure modes now handled at their own layer:

  • Delivery failures (a disposed/closed channel, a teardown race) are an expected lifecycle artifact. The worker forwards the log fire-and-forget and swallows the rejected send, so the late log is dropped instead of crashing the run — matching isolate: true where such logs are lost as the worker is torn down.
  • Handler failures (a user onConsoleLog filter or a reporter's onUserConsoleLog throwing) would otherwise be hidden by that swallow. The host now surfaces them where they occur, without failing the otherwise-passing run.

The change lives in the pool-agnostic worker/host paths, so it applies to both the forks and threads pools.

Originally surfaced while migrating Rsbuild's e2e runner to rstest (web-infra-dev/rsbuild#7776), then reduced to the minimal repro in #1367.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

Rsdoctor Bundle Diff Analysis

Found 13 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Change
adapter-rsbuild 3.7 KB 0
adapter-rspack 7.8 KB 0
adapter-rslib 24.7 KB 0
browser 2.0 MB 0
browser-react 3.7 KB 0
browser-ui 810.0 KB 0
coverage-istanbul 14.5 KB 0
coverage-v8 16.3 KB 0
core/browser 977.6 KB 0
core/loaders 869.0 B 0
core/main 1.7 MB +172.0 B (0.0%)
vscode/extension 27.0 MB 0
vscode/worker 14.5 KB 0
📋 Detailed Reports (Click to expand)

📁 core/main

Path: packages/core/.rsdoctor/main/rsdoctor-data.json

📌 Baseline Commit: f03b1dfff4 | PR: #1365

Metric Current Baseline Change
📊 Total Size 1.7 MB 1.7 MB +172.0 B (0.0%)
📄 JavaScript 1.6 MB 1.6 MB +172.0 B (0.0%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 81.6 KB 81.6 KB 0

📦 Download Diff Report: core/main Bundle Diff

Generated by Rsdoctor GitHub Action

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29bd5cd637

ℹ️ 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".

Comment thread packages/core/src/runtime/worker/runInPool.ts Outdated
@fi3ework fi3ework force-pushed the fix-late-console-rpc-closed branch from 29bd5cd to 0ae3aae Compare June 3, 2026 16:23

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ae3aaed9d

ℹ️ 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".

Comment thread packages/core/src/runtime/worker/runInPool.ts Outdated
@fi3ework fi3ework force-pushed the fix-late-console-rpc-closed branch 2 times, most recently from 3358328 to c85f73e Compare June 3, 2026 17:59
@fi3ework fi3ework changed the title fix(core): redirect console logs that outlive their test file (isolate: false) fix(core): prevent late console logs from failing the run (isolate: false) Jun 3, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c85f73e2b5

ℹ️ 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".

Comment thread packages/core/src/runtime/worker/rpc.ts Outdated
@fi3ework fi3ework force-pushed the fix-late-console-rpc-closed branch from c85f73e to 3fb6473 Compare June 3, 2026 18:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3fb6473777

ℹ️ 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".

Comment thread packages/core/src/runtime/worker/runInPool.ts
@fi3ework

fi3ework commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ 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".

…alse)

With `isolate: false`, all test files share one worker but each file owns its
own birpc channel. The host disposes a file's channel as soon as the file
finishes, while the worker only closes it when the next file starts. A console
reference captured by a file (e.g. a logger that flushes from a late
`setTimeout`/microtask) could fire in or after that window and forward the log
over a disposed/closed channel.

The console interceptor does not await the forward, so the rejected send
surfaced as an `unhandledRejection` (`[birpc] rpc is closed`) that failed the
run even though every assertion passed, and was misattributed to whichever file
happened to be running.

Console forwarding is best-effort, with two failure modes handled at their own
layer:

- Delivery failures (a disposed/closed channel, a teardown race) are an expected
  lifecycle artifact. The worker forwards the log fire-and-forget and swallows
  the rejected send, so the late log is dropped instead of crashing the run —
  matching `isolate: true` where such logs are lost as the worker is torn down.
- Handler failures (a user `onConsoleLog` filter or a reporter's
  `onUserConsoleLog` throwing) would otherwise be hidden by that swallow. The
  host now surfaces them where they occur, without failing the otherwise-passing
  run.

Covered by e2e regression tests (with console suppression) across the forks and
threads pools and both isolate modes, plus one for a throwing `onConsoleLog`
hook.

Originally surfaced while migrating Rsbuild's e2e runner to rstest
(web-infra-dev/rsbuild#7776), then reduced to the minimal repro in #1367.

Closes #1367
@fi3ework fi3ework force-pushed the fix-late-console-rpc-closed branch from 3fb6473 to ec5cde3 Compare June 4, 2026 04:59
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

pkg.pr.new preview ec5cde3 · workflow run

  • pnpm add https://pkg.pr.new/@rstest/adapter-rsbuild@ec5cde3
  • pnpm add https://pkg.pr.new/@rstest/adapter-rslib@ec5cde3
  • pnpm add https://pkg.pr.new/@rstest/adapter-rspack@ec5cde3
  • pnpm add https://pkg.pr.new/@rstest/browser@ec5cde3
  • pnpm add https://pkg.pr.new/@rstest/browser-react@ec5cde3
  • pnpm add https://pkg.pr.new/@rstest/core@ec5cde3
  • pnpm add https://pkg.pr.new/@rstest/coverage-istanbul@ec5cde3
  • pnpm add https://pkg.pr.new/@rstest/coverage-v8@ec5cde3

@fi3ework fi3ework merged commit d8598db into main Jun 4, 2026
15 checks passed
@fi3ework fi3ework deleted the fix-late-console-rpc-closed branch June 4, 2026 05:33
@9aoy 9aoy mentioned this pull request Jun 11, 2026
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.

[Bug]: "[birpc] rpc is closed" when a console call runs after a test file finishes (isolate: false)

1 participant