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(server): use --host duplicate port number (#12205) #12211

Closed
wants to merge 6 commits into from

Conversation

kinfuy
Copy link
Contributor

@kinfuy kinfuy commented Feb 26, 2023

Description

fix #12205
fix #12144
superseds close #10651
close #10638

When localhost(vite dev) is listening on port 5173, it's possible for 127.0.0.1(vite dev --host) to listen on port 5173 again.

Additional context

Re: #12208


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented Feb 27, 2023

📝 Ran ecosystem CI: Open

suite result
astro ✅ success
histoire ❌ failure
iles ✅ success
ladle ✅ success
laravel ✅ success
marko ✅ success
nuxt-framework ✅ success
previewjs ✅ success
qwik ✅ success
rakkas ✅ success
sveltekit ✅ success
vite-plugin-ssr ✅ success
vite-plugin-react ✅ success
vite-plugin-react-pages ❌ failure
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ✅ success
windicss ✅ success

if (port > 65535) {
reject(new Error('Port not found'))
}
const server = net.connect(port, host)
Copy link
Member

Choose a reason for hiding this comment

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

Interesting approach. I'm a bit worried about the inverted logic here. Are we sure that connect only fails when the port is unused? Could a used port still reject the connection making this logic invalid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked up a lot of data. It is only the IP or port number with invalid connection that fails.
Of course, I can't guarantee that this is correct.
I tested Node16 and Node18 in Windows and Mac, and they all work normally

patak-dev
patak-dev previously approved these changes Feb 27, 2023
Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Ecosystem CI is happy, including vite-setup-catalogue. I think we could merge this one to try it out during the beta period and revert later if it causes issues. @sapphi-red what do you think?

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Yeah, it's an interesting approach. I think it's a good idea to try this in beta.

packages/vite/src/node/http.ts Outdated Show resolved Hide resolved
packages/vite/src/node/http.ts Show resolved Hide resolved
packages/vite/src/node/http.ts Show resolved Hide resolved
Co-authored-by: 翠 / green <green@sapphi.red>
@sapphi-red
Copy link
Member

This fail might cause an issue. This PR's approach doesn't work well in a concurrent situation.
https://github.com/vitejs/vite/actions/runs/4292613465/jobs/7479273031#step:13:105

I guess this fail happened by the following steps:

  1. playground A: net.connect checks port 5173 => success
  2. playground B: net.connect checks port 5173 => success
  3. playground A: listen port 5173
  4. playground B: listen port 5173 => error

@sapphi-red
Copy link
Member

Umm, it failed 3 out of 7 times.

@kinfuy
Copy link
Contributor Author

kinfuy commented Mar 2, 2023

In this way, concurrency seems to be inevitable, and better methods need to be found 🤔

@kinfuy kinfuy closed this Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants