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

startDevWorker Milestone 1 - Reboot #4413

Merged
merged 41 commits into from
Nov 23, 2023

Conversation

RamIdeas
Copy link
Contributor

@RamIdeas RamIdeas commented Nov 9, 2023

What this PR solves / how to test:

This PR is for all changes made since Milestone 1 was first merged in #3960

Notable commits:

  • bedbe4e fix: don't show logs to ProxyWorker(s) unless log level is debug
  • 76f90ed fix: show console.log's in remote mode remote inspector websocket upgrade request required auth headers so use fetch with Upgrade: websocket header instead of new WebSocket
  • 1271a1a use miniflare verbose mode only if debug log level
    • should reduce "scary logs" noise
  • 7198a81 register ProxyWorker with DevRegistry instead of UserWorker
  • f09c51d Revert "register ProxyWorker with DevRegistry"
    • this commit has been applied+reverted and will be reapplied in Milestone 2 due to its dependence on the new bindings shape
    • it is an optimisation for the devregistry and functionally behaves the same
  • 1a9e2f5 use single Miniflare instance for (Inspector)ProxyWorker
  • 997d77d port: clear remote runtime logs upon UserWorker restarts
  • 6129d96 default unstable_dev inspectorPort to 0
    • this is a more sane default for unstable_dev which is used most in test suites and therefore most likely run in parallel
  • 7ac5efd parallelise cleanup to minimise chance of hanging
    • previously, sequential cleanups fail to fully cleanup if earlier steps in the sequence fail
  • 974216e ensure InspectorProxyWorker unsafeDirectPort is set
    • undefined disables the inspector – we should implement a separate option to explicitly enable/disable the inspector in Miniflare
  • 001c542 don't use file-system for (Inspector)ProxyWorker DOs
    • the DOs don't use storage so we can tell Miniflare to not bother setting up the tmp dirs
  • 3fea268 prevent eviction of the Durable Objects with (Inspector)ProxyWorker
    • Durable Object eviction was implemented and shipped during this work which caused the in-memory state to disappear across requests (interferring with pause/play control messages) – since these DOs are for local development, we can disable eviction entirely
  • 183db24 ready event should await proxyWorker.setOptions
    • workaround for miniflare bug
  • 7f768e6 remove miniflare workaround for parallel requests
    • removes a previous workaround
  • f72497e considerations for race between control messages and user fetches
    • this guarantees the order of requests for control messages and worker.fetch requests which are more likely to run into a race condition over the async http boundary than eye-ball requests
  • 0845c9d use port: undefined vs 0 for UserWorker to force different port across reloads to workaround workerd bug on Windows
  • 217d8ba Don't try to parse node internals
  • a49cc8a only proxy consoleAPICalled events in remote mode
  • a1d5afa enable consoleAPICalled events proxying if local mode AND service-worker format

Author has addressed the following:

  • Tests
    • Included
    • Not necessary because:
  • Changeset (Changeset guidelines)
    • Included
    • Not necessary because:
  • Associated docs
    • Issue(s)/PR(s): linked above
    • Not necessary because:

Note for PR author:

We want to celebrate and highlight awesome PR review! If you think this PR received a particularly high-caliber review, please assign it the label highlight pr review so future reviewers can take inspiration and learn from it.

Copy link

changeset-bot bot commented Nov 9, 2023

🦋 Changeset detected

Latest commit: 7506c8f

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

This PR includes changesets to release 1 package
Name Type
wrangler Minor

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

@RamIdeas RamIdeas changed the base branch from main to startDevWorker-release November 9, 2023 13:50
Copy link
Contributor

github-actions bot commented Nov 9, 2023

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/workers-sdk/runs/6962539379/npm-package-wrangler-4413

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

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6962539379/npm-package-wrangler-4413

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6962539379/npm-package-wrangler-4413 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6962539379/npm-package-miniflare-4413
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6962539379/npm-package-cloudflare-pages-shared-4413

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20231030.1
workerd 1.20231030.0 1.20231030.0
workerd --version 1.20231030.0 2023-10-30

|

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@RamIdeas RamIdeas marked this pull request as ready for review November 13, 2023 18:08
@RamIdeas RamIdeas requested a review from a team as a code owner November 13, 2023 18:08
@RamIdeas RamIdeas force-pushed the startDevWorker-release branch from 261f092 to e708f82 Compare November 14, 2023 14:36
@RamIdeas RamIdeas force-pushed the startDevWorker-milestone-1 branch 3 times, most recently from 8e2f1ce to 8b3c9b2 Compare November 15, 2023 02:43
@RamIdeas RamIdeas force-pushed the startDevWorker-milestone-1 branch from 1348f52 to ee9ac52 Compare November 16, 2023 15:15
Copy link

codecov bot commented Nov 16, 2023

Codecov Report

❗ No coverage uploaded for pull request base (startDevWorker-release@3dd2a65). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head e82dbcd differs from pull request most recent head 7506c8f. Consider uploading reports for the commit 7506c8f to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@                    Coverage Diff                    @@
##             startDevWorker-release    #4413   +/-   ##
=========================================================
  Coverage                          ?   75.48%           
=========================================================
  Files                             ?      240           
  Lines                             ?    12851           
  Branches                          ?     3309           
=========================================================
  Hits                              ?     9701           
  Misses                            ?     3150           
  Partials                          ?        0           

@RamIdeas RamIdeas added the e2e Run wrangler e2e tests on a PR label Nov 16, 2023
Copy link
Contributor

@mrbbot mrbbot left a comment

Choose a reason for hiding this comment

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

Nice! Nearly there... 😅 Added some comments.


type OptionalKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

beforeEach(() => {
devEnv = new DevEnv();
mf = undefined;
res = undefined;
res = undefined as any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Having | undefined in the res type rather than as any seems like a nicer solution here. Could we switch back to that and use runtime assertions/?. where needed?

packages/wrangler/src/dev/dev.tsx Show resolved Hide resolved
packages/wrangler/templates/startDevWorker/ProxyWorker.ts Outdated Show resolved Hide resolved
@RamIdeas RamIdeas force-pushed the startDevWorker-release branch from e708f82 to c569378 Compare November 20, 2023 16:44
@RamIdeas RamIdeas force-pushed the startDevWorker-milestone-1 branch from d6cad6b to b34416f Compare November 20, 2023 16:47
fixtures/worker-ts/src/index.ts Outdated Show resolved Hide resolved
packages/wrangler/src/dev/local.tsx Show resolved Hide resolved
packages/wrangler/src/dev/start-server.ts Show resolved Hide resolved
packages/wrangler/src/api/dev.ts Show resolved Hide resolved
@RamIdeas RamIdeas force-pushed the startDevWorker-milestone-1 branch from 719e4f9 to 9b2ba1b Compare November 21, 2023 18:47
@RamIdeas RamIdeas requested a review from a team as a code owner November 21, 2023 18:47
@RamIdeas RamIdeas force-pushed the startDevWorker-milestone-1 branch from 9b2ba1b to 2931c48 Compare November 21, 2023 18:49
@RamIdeas RamIdeas closed this Nov 21, 2023
@RamIdeas RamIdeas reopened this Nov 21, 2023
@RamIdeas RamIdeas force-pushed the startDevWorker-release branch from c569378 to e875506 Compare November 21, 2023 18:51
RamIdeas and others added 19 commits November 22, 2023 20:02
mainly, base innerUrl off of request.url not userWorkerUrl
using the MF-Disable-Pretty-Error header on the UserWorker request

the ProxyWorker will still interpret the json error response
depending on its own MF-Disable-Pretty-Error header
by trying to start on a random port
by removing --runInBand flag for jest
+ remove miniflare log.error overrides no longer needed
@RamIdeas RamIdeas force-pushed the startDevWorker-milestone-1 branch from 2931c48 to e82dbcd Compare November 22, 2023 20:03
@RamIdeas RamIdeas merged commit 29d7a4f into startDevWorker-release Nov 23, 2023
@RamIdeas RamIdeas deleted the startDevWorker-milestone-1 branch November 23, 2023 14:09
@RamIdeas RamIdeas mentioned this pull request Nov 23, 2023
6 tasks
RamIdeas added a commit that referenced this pull request Nov 23, 2023
* Revert "Revert "startDevWorker - Milestone 1" (#4171)"

This reverts commit 88f15f6.

* fix: don't show logs to ProxyWorker(s)
unless log level is debug

* fix: show console.log's in remote mode
remote inspector websocket upgrade request required auth headers
so use `fetch` with `Upgrade: websocket` header instead of `new WebSocket`

* use miniflare verbose mode only if debug log level

* use single Miniflare instance
for (Inspector)ProxyWorker

* port: clear remote runtime logs
upon UserWorker restarts

* default unstable_dev inspectorPort to 0

* parallelise cleanup to minimise chance of hanging
previously, sequential cleanups fail to fully cleanup if earlier steps in the sequence fail

* ensure InspectorProxyWorker unsafeDirectPort is set

* don't use file-system for (Inspector)ProxyWorker DOs

* prevent eviction of the Durable Objects
with (Inspector)ProxyWorker

* remove miniflare workaround for parallel requests

* considerations for race between control messages and user fetches

* use port: undefined vs 0 for UserWorker
to force different port across reloads to workaround workerd bug on Windows

* Don't try to parse `node-internal:* import specifiers

* improve InspectorProxyWorker debug logs

* only proxy consoleAPICalled events in remote mode

* enable consoleAPICalled events proxying if local mode AND service-worker format

* fix userWorkerInnerUrlOverrides host/hostname/port
mainly, base innerUrl off of request.url not userWorkerUrl

* use ProxyWorker ip/port for DEV_SERVER_READY event
instead of UserWorker ip/port

* always disable the UserWorker miniflare pretty error
using the MF-Disable-Pretty-Error header on the UserWorker request

the ProxyWorker will still interpret the json error response
depending on its own MF-Disable-Pretty-Error header

* recover from 'address in use' errors
by trying to start on a random port

* run unit tests in parallel again
by removing --runInBand flag for jest

* add handleRuntimeStdio option to ProxyWorker miniflare instance

* expand containsHexStack check for windows

* logger.debug runtime websocket errors from InspectorProxyWorker
+ remove miniflare log.error overrides no longer needed

* log workerd warnings with logger.warn
not logger.error/info

* enable Cloudflare Access auth for remote previews

* only send Runtime.discardConsoleEntries if currently connected to runtime

---------

Co-authored-by: Samuel Macleod <[email protected]>
Co-authored-by: MrBBot <[email protected]>
penalosa added a commit that referenced this pull request Nov 23, 2023
* Revert "Revert "startDevWorker - Milestone 1" (#4171)"

This reverts commit 88f15f6.

* fix: don't show logs to ProxyWorker(s)
unless log level is debug

* fix: show console.log's in remote mode
remote inspector websocket upgrade request required auth headers
so use `fetch` with `Upgrade: websocket` header instead of `new WebSocket`

* use miniflare verbose mode only if debug log level

* use single Miniflare instance
for (Inspector)ProxyWorker

* port: clear remote runtime logs
upon UserWorker restarts

* default unstable_dev inspectorPort to 0

* parallelise cleanup to minimise chance of hanging
previously, sequential cleanups fail to fully cleanup if earlier steps in the sequence fail

* ensure InspectorProxyWorker unsafeDirectPort is set

* don't use file-system for (Inspector)ProxyWorker DOs

* prevent eviction of the Durable Objects
with (Inspector)ProxyWorker

* remove miniflare workaround for parallel requests

* considerations for race between control messages and user fetches

* use port: undefined vs 0 for UserWorker
to force different port across reloads to workaround workerd bug on Windows

* Don't try to parse `node-internal:* import specifiers

* improve InspectorProxyWorker debug logs

* only proxy consoleAPICalled events in remote mode

* enable consoleAPICalled events proxying if local mode AND service-worker format

* fix userWorkerInnerUrlOverrides host/hostname/port
mainly, base innerUrl off of request.url not userWorkerUrl

* use ProxyWorker ip/port for DEV_SERVER_READY event
instead of UserWorker ip/port

* always disable the UserWorker miniflare pretty error
using the MF-Disable-Pretty-Error header on the UserWorker request

the ProxyWorker will still interpret the json error response
depending on its own MF-Disable-Pretty-Error header

* recover from 'address in use' errors
by trying to start on a random port

* run unit tests in parallel again
by removing --runInBand flag for jest

* add handleRuntimeStdio option to ProxyWorker miniflare instance

* expand containsHexStack check for windows

* logger.debug runtime websocket errors from InspectorProxyWorker
+ remove miniflare log.error overrides no longer needed

* log workerd warnings with logger.warn
not logger.error/info

* enable Cloudflare Access auth for remote previews

* only send Runtime.discardConsoleEntries if currently connected to runtime

---------

Co-authored-by: Samuel Macleod <[email protected]>
Co-authored-by: MrBBot <[email protected]>
@admah admah added this to the Wrangler as a Library milestone Jan 9, 2024
@lrapoport-cf lrapoport-cf linked an issue Jan 10, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run wrangler e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Stabilizing unstable_dev and expanding Wrangler as an API
5 participants