Skip to content

fix(vitest-pool-workers): dispose remote proxy sessions on pool close#12682

Merged
dario-piotrowicz merged 5 commits intocloudflare:mainfrom
hiendv:clean-up-remote-proxy
Mar 2, 2026
Merged

fix(vitest-pool-workers): dispose remote proxy sessions on pool close#12682
dario-piotrowicz merged 5 commits intocloudflare:mainfrom
hiendv:clean-up-remote-proxy

Conversation

@hiendv
Copy link
Copy Markdown
Contributor

@hiendv hiendv commented Feb 26, 2026

Summary

  • Dispose RemoteProxySession objects during vitest-pool-workers pool shutdown to prevent hanging processes
  • Export remoteProxySessionsDataMap from config.ts so it can be iterated and cleared in the close() handler
  • Add E2E test using --reporter=hanging-process to verify no hanging process warning appears

Background

When a test project uses bindings that require a remote proxy (e.g. AI bindings), the pool creates RemoteProxySession objects that wrap long-running dev worker processes. These sessions were never disposed during pool shutdown, causing vitest processes to hang after tests complete ("prevents Vite server from exiting" symptom).

Reproduction

import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";

export default defineWorkersConfig({
  test: {
    poolOptions: {
      workers: {
        wrangler: { configPath: "./wrangler.jsonc" },
      },
    },
  },
});
export default {
  async fetch(): Promise<Response> {
    return new Response("Hello");
  },
};
import { SELF } from "cloudflare:test";
import { it, expect } from "vitest";

it("responds with Hello", async () => {
  const response = await SELF.fetch("http://localhost/");
  expect(await response.text()).toBe("Hello");
});
pnpm test run --reporter=hanging-process src/index.test.ts
pnpm test run --reporter=hanging-process src/index.test.ts

> vitest-ai-hang-repro@ test /tmp/vpw-hang
> vitest run run --reporter\=hanging-process src/index.test.ts

▲ [WARNING] AI bindings always access remote resources, and so may incur usage charges even in local dev. To suppress this warning, set `remote: true` for the binding definition in your configuration file.


[vpw:debug] Adding `enable_nodejs_tty_module` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:debug] Adding `enable_nodejs_fs_module` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:debug] Adding `enable_nodejs_http_modules` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:debug] Adding `enable_nodejs_perf_hooks_module` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:info] Starting isolated runtimes for vitest.config.ts...
[vpw:debug] Shutting down runtimes...
There are 150 handle(s) keeping the process running

# FSEVENTWRAP
/tmp/vpw-hang/node_modules/.pnpm/wrangler@4.68.1/node_modules/wrangler/wrangler-dist/cli.js:123596 - return fs23.watch(path82, {
/tmp/vpw-hang/node_modules/.pnpm/wrangler@4.68.1/node_modules/wrangler/wrangler-dist/cli.js:123956 - watcher = createFsWatchInstance(
/tmp/vpw-hang/node_modules/.pnpm/wrangler@4.68.1/node_modules/wrangler/wrangler-dist/cli.js:124077 - closer = setFsWatchListener(path82, absolutePath, options, {
/tmp/vpw-hang/node_modules/.pnpm/wrangler@4.68.1/node_modules/wrangler/wrangler-dist/cli.js:124133 - const closer = this._watchWithNodeFs(file3, listener);
/tmp/vpw-hang/node_modules/.pnpm/wrangler@4.68.1/node_modules/wrangler/wrangler-dist/cli.js:124330 - closer = this._handleFile(wh.watchPath, stats, initialAdd);
/tmp/vpw-hang/node_modules/.pnpm/wrangler@4.68.1/node_modules/wrangler/wrangler-dist/cli.js:124671 - const res = await this._nodeFsHandler._addToNodeFs(path82, !_internal, void 0, 0, _origAdd);

# FILEHANDLE
(unknown stack trace)

# FILEHANDLE
(unknown stack trace)

# FILEHANDLE
(unknown stack trace)

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: it's an internal behavior

Open with Devin

@hiendv hiendv requested a review from a team as a code owner February 26, 2026 11:23
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 26, 2026

🦋 Changeset detected

Latest commit: a03a842

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

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

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 26, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12682

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12682

miniflare

npm i https://pkg.pr.new/miniflare@12682

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12682

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12682

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12682

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12682

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12682

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12682

wrangler

npm i https://pkg.pr.new/wrangler@12682

commit: a783cf3

@hiendv hiendv force-pushed the clean-up-remote-proxy branch from 71853d7 to 3413424 Compare February 26, 2026 14:16
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

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

This is great! Thanks a lot @hiendv! 🫶

I've left two non-blocking minor comments please have a look 🙂🙏

In any case everything else is great for me and I also manually checked this PR prerelease and I can confirm that it fixes the issue perfectly 🙏

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Feb 28, 2026
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Before we merge this can someone check it actually works with the real CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API token, since this test will not be run on this forked PR.

@github-project-automation github-project-automation bot moved this from Approved to In Review in workers-sdk Mar 2, 2026
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

In any case everything else is great for me and I also manually checked this PR prerelease and I can confirm that it fixes the issue perfectly 🙏

Oh sorry @dario-piotrowicz - I missed this.

@github-project-automation github-project-automation bot moved this from In Review to Approved in workers-sdk Mar 2, 2026
@dario-piotrowicz
Copy link
Copy Markdown
Member

@hiendv we had some CI issues that got fixed, I think your PR needs to be rebased in order for its CI checks to go green, could you do that? 🙂 (if you prefer I can rebase for you, just let me know 🙂)

@hiendv hiendv force-pushed the clean-up-remote-proxy branch from 88e0515 to a03a842 Compare March 2, 2026 14:53
@dario-piotrowicz dario-piotrowicz merged commit b5b91c9 into cloudflare:main Mar 2, 2026
32 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 2, 2026
@dario-piotrowicz
Copy link
Copy Markdown
Member

Awesome! Thanks a lot for the contribution @hiendv 🫶

This change will be part of tomorrow's release 🚀

@hiendv hiendv deleted the clean-up-remote-proxy branch March 2, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants