Skip to content

fix(dev): close upgraded sockets and resolve on worker shutdown timeout - #4671

Open
danielroe wants to merge 3 commits into
v2from
fix/dev-socket-shutdown
Open

danielroe wants to merge 3 commits into
v2from
fix/dev-socket-shutdown

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

nuxt/cli#1531
nuxt/cli#1532
resolves #4610

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

if a websocket connection to the dev worker is still open when the dev server closes, close() never resolves. the upstream nuxt/cli issue was that nuxt dev just hung for 15s (windows only, interestingly) until it hit a timeout:

 WARN  force closing dev worker...
▲  The dev server did not shut down within 15s: ... 1 open connection ... Exiting anyway.

w've worked around this in nuxt/cli#1532, but I think this is a bug worth fixing in nitro too (I've included a pure-nitro regression test that times out without the fix)

the issue is that:

  1. in the worker, closeAllConnections doesn't cover upgraded sockets, so listener.close() waits as long as the websocket stays open and we never send the exit event
  2. in #closeWorker, the graceful-shutdown timeout logs but never resolves

so, this PR destroys any upgraded sockets in shutdown() alongside closeAllConnections(), and resolves on timeout so we fall through to terminate() as intended

I think the reason existing tests didn't catch it was that we skip the graceful wait in test/CI environments. I've mocked std-env in the new test so we can avoid a regression in future

many thanks to @userquin for his helpful work finding the cause and opening issues in nuxt/cli + nitro ❤️

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe
danielroe requested a review from pi0 as a code owner September 26, 2026 12:15
@vercel

vercel Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro.build Ready Ready Preview Sep 26, 2026 12:23pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: b00db222-ce61-4c79-9f9d-b2e17eaffe5c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitropack@4671

commit: f3b2a50

@danielroe

Copy link
Copy Markdown
Member Author

the failing test is also failing on v2

@userquin

userquin commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Nice, using nitropack at nuxt cli playground works.

Without this PR via pkg-pr-new (just the merged pr at nuxt cli, I guess it is the missing resolve at src/core/dev-server/worker.ts):
image

With this PR via pkg-pr-new with 3 tabs at /ws:
image

This branch was successfully deployed

1 active deployment
Preview — f3b2a505 Deployed Sep 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants