Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: No clean shutdown possible as child_process, results in workerd zombie proccesses #4131

Closed
alexanderniebuhr opened this issue Oct 6, 2023 · 2 comments · Fixed by #4635
Labels
bug Something that isn't working

Comments

@alexanderniebuhr
Copy link
Contributor

alexanderniebuhr commented Oct 6, 2023

Which Cloudflare product(s) does this pertain to?

Wrangler core

What version(s) of the tool(s) are you using?

3.11.0

What version of Node are you using?

No response

What operating system are you using?

Mac

Describe the Bug

At Astro we are using the following code to run wrangler in our test suite. We do have issues with the teardown. The only way we see is to kill the child_process, however this does not work, because https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/pages/dev.ts#L662 does not return, and therefore the CLEANUP does not work. This is also seen in the logs below, where I added a bunch of console logs after each line

This is our debug script:

const wranglerPath = fileURLToPath(new URL('../node_modules/wrangler/bin/wrangler.js', import.meta.url));
/** Returns a process running the Astro CLI. */
export function wranglerCli(cwd) {
	const spawned = execa(wranglerPath, ['pages',
		'dev',
		'dist',
		'--port',
		'8788',
		'--log-level',
		'debug'], {
		env: { CI: 1, CF_PAGES: 1 },
		cwd: cwd
	});

	spawned.stdout.setEncoding('utf8');

	return spawned;
}

let wrangler
wrangler = wranglerCli(process.cwd());
wrangler.stdout.on("data", (data) => {
  console.log(data);
});

setTimeout(() => {
  console.log("KILLING")
  wrangler.kill("SIGINT")
  console.log("DONE")
}, 10000);

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

Logs using wrangler directly

❯ NO_COLOR=1 CI=1 CF_PAGES=1 "/Users/alexanderniebuhr/Developer/Projects/withastro_adapters/packages/cloudflare/node_modules/.bin/wrangler" pages dev dist --log-level debug
▲ [WARNING] No compatibility_date was specified. Using today's date: 2023-10-06.

  Pass it in your terminal:
  --compatibility-date=2023-10-06
  See https://developers.cloudflare.com/workers/platform/compatibility-dates/ for more information.


✨ Compiled Worker successfully
 ⛅️ wrangler 3.11.0
-------------------
▲ [WARNING] --local is no longer required and will be removed in a future version.

  `wrangler dev` now uses the local Cloudflare Workers runtime by default. 🎉


Metrics dispatcher: Posting data {"type":"event","name":"run dev","properties":{"local":true,"usesTypeScript":false}}
Using vars defined in .dev.vars
Your worker has access to the following bindings:
- Vars:
  - COOL: "ME"
  - DATABASE_URL: "(hidden)"
⎔ Starting local server...
[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2023-10-02",
but you've requested "2023-10-06". Falling back to "2023-10-02"...
workerd/server/server.c++:2624: info: Inspector is listening
[mf:inf] Ready on http://0.0.0.0:8788
[mf:inf] - http://127.0.0.1:8788
[mf:inf] - http://192.168.1.160:8788
[mf:inf] - http://198.19.249.3:8788
[mf:inf] - http://172.19.0.0:8788
[mf:inf] - http://172.22.0.0:8788
[mf:inf] - http://172.23.0.0:8788
DEBUG
Metrics dispatcher: Posting data {"type":"event","name":"run pages dev","properties":{}}
[ [AsyncFunction: stop] ]
BEFORE_PROCESS
BEFORE_WAIT
workerd/server/server.c++:1099: info: Inspector client attaching [core:user:test]
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ [b] open a browser, [d] open Devtools, [c] clear console, [x] to exit                                                                                                                                                                             │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
WAITED
CLEANING
CLEANED
CLEANING
⎔ Shutting down local server...

Logs using wrangler as child_process

❯ node trial.mjs
✨ Compiled Worker successfully

 ⛅️ wrangler 3.11.0
-------------------

Metrics dispatcher: Posting data {"type":"event","name":"run dev","properties":{"local":true,"usesTypeScript":false}}

Using vars defined in .dev.vars

Your worker has access to the following bindings:
- Vars:
  - COOL: "ME"
  - DATABASE_URL: "(hidden)"

⎔ Starting local server...

[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2023-10-02",
but you've requested "2023-10-06". Falling back to "2023-10-02"...

[mf:inf] Ready on http://0.0.0.0:8788

[mf:inf] - http://127.0.0.1:8788

[mf:inf] - http://192.168.1.160:8788
[mf:inf] - http://198.19.249.3:8788
[mf:inf] - http://172.19.0.0:8788
[mf:inf] - http://172.22.0.0:8788
[mf:inf] - http://172.23.0.0:8788

DEBUG

Metrics dispatcher: Posting data {"type":"event","name":"run pages dev","properties":{}}

[ [AsyncFunction: stop] ]
BEFORE_PROCESS

BEFORE_WAIT

KILLING
DONE
@alexanderniebuhr alexanderniebuhr added the bug Something that isn't working label Oct 6, 2023
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Oct 6, 2023
@Sammy-T
Copy link

Sammy-T commented Oct 9, 2023

I see this on Windows as well. I end up leaving Task Manager up to kill the process before I can run wrangler again.

@bkniffler
Copy link

Same issue with my worker, irrelevant if I use unstable_dev or spawn a child via wrangler dev. My worker has a few resources (queue, durable object etc) and I see quite a few workerd processes remaining after killing/stopping the worker after my tests. Also need to use my activity monitor / task manager to kill them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants