Skip to content

fix: pass plugin-mode listen errors to the watch callback - #5787

Merged
alexander-akait merged 4 commits into
mainfrom
fix/plugin-listen-error
Nov 12, 2026
Merged

alexander-akait merged 4 commits into
mainfrom
fix/plugin-listen-error

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #5782

In plugin mode, a listen() failure (e.g. EADDRINUSE) was only logged from the done hook, so watch() callers never saw it and the build kept running with no server. The listen is still started once from the aggregate done, and is now awaited from each Compiler's async done hook: the compiler itself, or every child of a MultiCompiler (whose aggregate done fires inside the last child's done). The error now reaches the watch() callback and webpack stops watching, like start() rejecting.

Port already taken, compiler.watch({}, (err) => …):

single Compiler MultiCompiler
before err is null, error only logged err is null, error only logged
after err.code === "EADDRINUSE" err.code === "EADDRINUSE"

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes, test/e2e/api-plugin.test.js: "should propagate listen errors via the watch callback" for a single compiler and for a MultiCompiler, both with a real occupied port. They replace "should log a listen() failure instead of throwing", which asserted the old behavior.

Does this PR introduce a breaking change?

No. The error goes to the watch() callback instead of the logger.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a

Use of AI

Claude Code wrote the fix and the tests. It confirmed the new tests fail without the fix, and it ran test/e2e/api-plugin.test.js and npm run lint locally.


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Plugin-mode server startup failures, including port conflicts, are now reported through the compiler’s watch callback instead of being logged while watching continues. This applies to both single-compiler and MultiCompiler setups.
    • Shutdown now waits for pending setup and listening operations to finish, helping ensure the server and compilers close cleanly after a startup failure.

In plugin mode the server is started from the aggregate `done` hook and a
`listen()` failure such as `EADDRINUSE` was only logged, so the watch build
kept running without a server. Await the listen from each `Compiler`'s
async `done` hook (every child of a `MultiCompiler`), so the error reaches
the `watch()` callback.

Fixes #5782

Claude-Session: https://claude.ai/code/session_013FhutSnStkMpV2mZSNb8M9
@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f6551dd

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

This PR includes changesets to release 1 package
Name Type
webpack-dev-server 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

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

In plugin mode, the server retains its setup-and-listen promise. Compiler done hooks await that promise and forward listen failures to the watch() callback. Tests cover port conflicts for single-compiler and MultiCompiler setups, and a patch changeset documents the behavior.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to f6551

Plugin-mode listen failures such as EADDRINUSE now reach the watch() callback, as the linked issue requested. No concrete merge-blocking risk was found in this change.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #5782 requires that a plugin-mode listen failure, such as EADDRINUSE, reaches the watch() callback, as start() rejection does. The AI-generated summary of lib/Server.js describes the required me… Make the changed blobs for lib/Server.js and test/e2e/api-plugin.test.js available in the checkout, or provide a readable diff of Server.apply. Confirm that the listen promise is awaited from the single Compiler done hook and from each Mult…
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: plugin-mode listen errors (such as EADDRINUSE) are now passed to the watch() callback instead of only being logged. The raw summary confirms Server.js now makes each …
Out of Scope Changes check Passed The reported changed files are .changeset/plugin-listen-error.md, lib/Server.js, and test/e2e/api-plugin.test.js. The changeset documents the fix. lib/Server.js carries the listen-error propagation fo…
Full details: Title check

Explanation

The title states the main change: plugin-mode listen errors (such as EADDRINUSE) are now passed to the watch() callback instead of only being logged. The raw summary confirms Server.js now makes each compiler's async done hook await the pending listen promise, so listen failures reject the watch callback. The tests were updated to match. The title is short, specific, and uses a conventional fix: prefix.

Full details: Out of Scope Changes check

Explanation

The reported changed files are .changeset/plugin-listen-error.md, lib/Server.js, and test/e2e/api-plugin.test.js. The changeset documents the fix. lib/Server.js carries the listen-error propagation for issue #5782. The test file replaces the logging-only assertion with watch-callback assertions for the same issue. The changes since the previous review are described as within the same listen-error path. No unrelated change is identified in the available summaries. The file-level line counts were not checked against readable diffs, because the diffs were unavailable.

Full details: Linked Issues check

Explanation

Issue #5782 requires that a plugin-mode listen failure, such as EADDRINUSE, reaches the watch() callback, as start() rejection does. The AI-generated summary of lib/Server.js describes the required mechanism: a retained pending listen promise that each compiler's async done hook awaits, including MultiCompiler children. The summary also describes e2e tests for a single Compiler and a MultiCompiler with an occupied port. The previous PASS relied on code at an earlier head. The changes since that review cannot be read: the whole-PR and incremental diffs for lib/Server.js and test/e2e/api-plugin.test.js returned 'changed blobs are missing from the existing checkout'. The head file read of lib/Server.js was truncated at 16000 bytes before the Server.apply section, so the current code and test assertions were not verified.

Resolution

Make the changed blobs for lib/Server.js and test/e2e/api-plugin.test.js available in the checkout, or provide a readable diff of Server.apply. Confirm that the listen promise is awaited from the single Compiler done hook and from each MultiCompiler child done hook, and that the watch callback receives EADDRINUSE in both e2e tests.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7ca38d17-a387-4529-8430-4069adb389c8
Commits

Reviewing files that changed from the base of the PR and between 36debd1 and f6551dd.

Files selected for processing: 1

  • lib/Server.js
Files skipped from review as they are similar to previous changes: 1

  • lib/Server.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

`api-plugin`, `event-source` and `hot-and-live-reload` all rewrote
`test/fixtures/reload-config/main.css`, and `node --test` runs files in
parallel, so a test could see another file's colour or an extra rebuild.
Give `api-plugin` and `event-source` their own copies, as `progress`
already does with `reload-config-2`.

Claude-Session: https://claude.ai/code/session_013FhutSnStkMpV2mZSNb8M9
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.82%. Comparing base (9a6472e) to head (f6551dd).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5787      +/-   ##
==========================================
+ Coverage   95.80%   95.82%   +0.02%     
==========================================
  Files           6        6              
  Lines        5551     5586      +35     
==========================================
+ Hits         5318     5353      +35     
  Misses        233      233              

☔ 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.

@alexander-akait
alexander-akait merged commit 6421747 into main Nov 12, 2026
17 checks passed
@alexander-akait
alexander-akait deleted the fix/plugin-listen-error branch November 12, 2026 11:25
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.

Plugin mode: listen failure is only logged, watch build keeps running without a dev server

1 participant