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

Allow --experimental-local to cleanly exit on x/CTRL-C #2400

Merged
merged 4 commits into from
Dec 15, 2022

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Dec 13, 2022

What this PR solves / how to test:

In the bootstrapper script bin/wrangler.js, we open an IPC channel, so IPC messages from the Wrangler process are propagated through the bootstrapper. Normally, Node's SIGINT handler would close this for us, but interactive mode enables raw mode on stdin which disables the built-in handler. This PR calls process.disconnect() to close this channel when we press x or CTRL-C, ensuring no open handles, and allowing for a clean exit.

This PR can be tested by running wrangler dev --experimental-local on a simple Worker script, then pressing, x, q and/or CTRL-C.

Associated docs issues/PR:

N/A

Author has included the following, where applicable:

Reviewer has performed the following, where applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

Fixes #2387

In the bootstrapper script `bin/wrangler.js`, we open an IPC channel,
so IPC messages from the Wrangler process are propagated through the
bootstrapper. Normally, Node's SIGINT handler would close this for
us, but interactive mode enables raw mode on stdin which disables the
built-in handler. This PR calls `process.disconnect()` to close this
channel when we press `x` or CTRL-C, ensuring no open handles, and
allowing for a clean exit.

Closes #2387
@mrbbot mrbbot requested a review from a team as a code owner December 13, 2022 12:29
@changeset-bot
Copy link

changeset-bot bot commented Dec 13, 2022

🦋 Changeset detected

Latest commit: b3540d5

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

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 13, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/runs/3703857564/npm-package-wrangler-2400

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/prs/2400/npm-package-wrangler-2400

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/runs/3703857564/npm-package-wrangler-2400 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/runs/3703857564/npm-package-cloudflare-pages-shared-2400

@codecov
Copy link

codecov bot commented Dec 13, 2022

Codecov Report

Merging #2400 (b3540d5) into main (df9d555) will increase coverage by 0.80%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2400      +/-   ##
==========================================
+ Coverage   70.71%   71.51%   +0.80%     
==========================================
  Files         154      155       +1     
  Lines        9758     9697      -61     
  Branches     2551     2537      -14     
==========================================
+ Hits         6900     6935      +35     
+ Misses       2858     2762      -96     
Impacted Files Coverage Δ
packages/wrangler/src/dev.tsx 84.74% <75.00%> (-0.17%) ⬇️
.../wrangler/src/__tests__/helpers/msw/handlers/r2.ts 52.94% <0.00%> (-11.77%) ⬇️
packages/wrangler/src/cfetch/internal.ts 57.01% <0.00%> (-0.38%) ⬇️
packages/wrangler/src/dev/local.tsx 22.14% <0.00%> (-0.17%) ⬇️
packages/wrangler/src/cfetch/index.ts 92.42% <0.00%> (-0.12%) ⬇️
packages/wrangler/src/logger.ts 100.00% <0.00%> (ø)
packages/wrangler/src/user/index.ts 100.00% <0.00%> (ø)
packages/wrangler/src/miniflare-cli/assets.ts
packages/wrangler/src/user/env-vars.ts
packages/wrangler/src/environment-variables.ts
... and 9 more

Copy link
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.

Accepting that a proper test for this will be added in #2365 - LGTM.
Nice comments.

Copy link
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.

Hmm... actually, I just tried the preview build of this:

pwd
> wrangler2/fixtures/worker-app
npx https://prerelease-registry.devprod.cloudflare.dev/runs/3685399221/npm-package-wrangler-2400 dev --experimental-local

And I still had to add the extra Ctrl-C after pressing Q.

Copy link
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.

Sorry, I was falling foul of the old wrangler uses the local install concern.
After deleting node_modules and locally installing the version from this PR - it all looks good.

Copy link
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

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

LGTM! Is this a concern for unstable_dev?

@mrbbot
Copy link
Contributor Author

mrbbot commented Dec 14, 2022

Is this a concern for unstable_dev?

Good question. This is potentially a concern if testMode: false is specified (not the default). In that case, if the user starts the script invoking unstable_dev with an IPC channel, that will be disconnected when UnstableDevWorker#stop is called. I guess we shouldn't do this when calling from unstable_dev?

@mrbbot
Copy link
Contributor Author

mrbbot commented Dec 14, 2022

@penalosa addressed in 538a008 👍

@mrbbot mrbbot merged commit 08a0b22 into main Dec 15, 2022
@mrbbot mrbbot deleted the bcoll/experimental-local-clean-exit branch December 15, 2022 14:03
@github-actions github-actions bot mentioned this pull request Dec 15, 2022
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: wrangler dev --experimental-local doesn't cleanly shut down the server
3 participants