Skip to content

fix: allow binding when strictPort is set but wildcard port is in use#22150

Merged
sapphi-red merged 10 commits intomainfrom
copilot/fix-vite-server-host-ip-issue
Apr 13, 2026
Merged

fix: allow binding when strictPort is set but wildcard port is in use#22150
sapphi-red merged 10 commits intomainfrom
copilot/fix-vite-server-host-ip-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

When server.host is set to a specific IP (e.g. 127.0.20.4) and strictPort: true, Vite's port availability pre-check tests 0.0.0.0 and ::. If any service holds the same port on a different interface, this wildcard check fails and Vite incorrectly aborts — even when the configured host:port is free.

Changes

  • packages/vite/src/node/http.ts: In httpServerStart, when strictPort is set and the wildcard pre-check fails, Vite now attempts to bind to the configured host:port directly before giving up. On success, a warning is emitted that another server may be running on a wildcard IP. On EADDRINUSE, falls back to the existing strictPort throw.

  • packages/vite/src/node/__tests__/http.spec.ts: Added tests covering: strictPort: true allows binding when wildcard port is in use; warning is emitted in that case; error still thrown when the configured host port is also occupied.

Example

// vite.config.js — previously failed with "Port 80 is already in use"
// even when 127.0.20.4:80 was free (other services on 127.0.10.x:80)
export default defineConfig({
  server: {
    host: '127.0.20.4',
    port: 80,
    strictPort: true,
  },
})

Copilot AI and others added 2 commits April 6, 2026 04:04
… variable names in tests

Agent-Logs-Url: https://github.com/vitejs/vite/sessions/9201cbf8-eb3b-4af9-965b-ca88e42eda6a

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Vite server rejection of specific IP binding fix: allow specific IP host binding when wildcard port is in use Apr 6, 2026
Copilot AI requested a review from sapphi-red April 6, 2026 04:07
Comment thread packages/vite/src/node/http.ts Outdated
…ondition

Agent-Logs-Url: https://github.com/vitejs/vite/sessions/1310d5a7-55fd-498d-9b49-e3224f8aa89a

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot AI changed the title fix: allow specific IP host binding when wildcard port is in use fix: allow binding when strictPort is set but wildcard port is in use Apr 6, 2026
Copilot AI requested a review from sapphi-red April 6, 2026 04:34
@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) feat: dev dev server labels Apr 6, 2026
@sapphi-red sapphi-red marked this pull request as ready for review April 6, 2026 06:18
Comment thread packages/vite/src/node/http.ts Outdated
@sapphi-red sapphi-red merged commit dfc8aa5 into main Apr 13, 2026
17 checks passed
@sapphi-red sapphi-red deleted the copilot/fix-vite-server-host-ip-issue branch April 13, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: dev dev server p2-edge-case Bug, but has workaround or limited in scope (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server.host specific IP still fails because Vite pre-checks 0.0.0.0/:: before binding

3 participants