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

fix: add warning to fetch() calls that will change the requested port #992

Merged
merged 1 commit into from
Jun 28, 2022

Conversation

petebacondarwin
Copy link
Contributor

@petebacondarwin petebacondarwin commented May 13, 2022

In Workers published to the Edge (rather than previews) there is a bug where a custom port on a downstream fetch request is ignored, defaulting to the standard port.
For example, https://my.example.com:668 will actually send the request to https://my.example.com:443.

This does not happen when using wrangler dev (both in remote and local mode), but to ensure that developers are aware of it this change displays a runtime warning in the console when the bug is hit.

Closes #1320

@changeset-bot
Copy link

changeset-bot bot commented May 13, 2022

🦋 Changeset detected

Latest commit: 5464941

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 May 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.developers.workers.dev/runs/2575542454/npm-package-wrangler-992

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

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/992/npm-package-wrangler-992

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/2575542454/npm-package-wrangler-992 dev path/to/script.js

@petebacondarwin petebacondarwin force-pushed the fetch-warning branch 2 times, most recently from b058786 to 65ad2fc Compare June 28, 2022 09:46
@petebacondarwin
Copy link
Contributor Author

If you are interested in testing this locally, you can try adding the following fetch requests to a Worker and running wrangler dev:

await fetch("http://portquiz.net");
await fetch("https://portquiz.takao-tech.com");
await fetch("http://portquiz.net:8989");
await fetch("https://portquiz.takao-tech.com:8989");
await fetch("http://portquiz.net");
await fetch("https://portquiz.takao-tech.com");
await fetch("http://portquiz.net:8988");
await fetch("https://portquiz.takao-tech.com:8988");
await fetch("http://portquiz.net");
await fetch("https://portquiz.takao-tech.com");
await fetch("http://portquiz.net:8989");
await fetch("https://portquiz.takao-tech.com:8989");

In Workers published to the Edge (rather than previews) there is a bug where a custom port on a downstream fetch request is ignored, defaulting to the standard port.
For example, `https://my.example.com:668` will actually send the request to `https://my.example.com:443`.

This does not happen when using `wrangler dev` (both in remote and local mode), but to ensure that developers are aware of it this change displays a runtime warning in the console when the bug is hit.

Closes cloudflare#1320
Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

Been looking forward to this one. This is the sort of thing wrangler should be doing, adds real value to using it. Thank you very much!

@petebacondarwin petebacondarwin merged commit ee6b413 into cloudflare:main Jun 28, 2022
@petebacondarwin petebacondarwin deleted the fetch-warning branch June 28, 2022 11:27
@github-actions github-actions bot mentioned this pull request Jun 28, 2022
@jfsiii
Copy link

jfsiii commented Jun 28, 2022

I really appreciate this fix, but don't understand how adding a warning fixes #1320. The behavior described in #1320 is still present, right? The user now has a much better understanding of what's going on, but any custom port will still be replaced.

@threepointone
Copy link
Contributor

Yeah good point. I reopened the issue, let's close it only once we ship the fix in the runtime.

threepointone added a commit that referenced this pull request Jul 19, 2022
In #992, we added a dev-only helper that would warn when using `fetch()` in a manner that wouldn't work as expected (because of a bug we currently have in the runtime). We did this by injecting a file that would override usages of `fetch()`. When using pnp style package managers like yarn, this file can't be resolved correctly. So to fix that, we extract it into the temporary destination directory that we use to build the worker (much like a similar fix we did in #1154)

Reported at #1320 (comment)
threepointone added a commit that referenced this pull request Jul 19, 2022
In #992, we added a dev-only helper that would warn when using `fetch()` in a manner that wouldn't work as expected (because of a bug we currently have in the runtime). We did this by injecting a file that would override usages of `fetch()`. When using pnp style package managers like yarn, this file can't be resolved correctly. So to fix that, we extract it into the temporary destination directory that we use to build the worker (much like a similar fix we did in #1154)

Reported at #1320 (comment)
@github-actions github-actions bot mentioned this pull request Jul 19, 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.

Fetch ignoring port
4 participants