Title: `createDevServer` starts on a port that another server holds on `127.0.0.1` · Issue #460 · devframes/devframe · GitHub
Open Graph Title: `createDevServer` starts on a port that another server holds on `127.0.0.1` · Issue #460 · devframes/devframe
X Title: `createDevServer` starts on a port that another server holds on `127.0.0.1` · Issue #460 · devframes/devframe
Description: Summary If another server listens on 127.0.0.1:
Open Graph Description: Summary If another server listens on 127.0.0.1:
X Description: Summary If another server listens on 127.0.0.1:<port>, createDevServer still starts on the same port and reports no error. With the default host localhost, devframe binds only [::1]:<port&...
Opengraph URL: https://github.com/devframes/devframe/issues/460
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`createDevServer` starts on a port that another server holds on `127.0.0.1`","articleBody":"### Summary\n\nIf another server listens on `127.0.0.1:\u003cport>`, `createDevServer` still starts on the same port and reports no error. With the default host `localhost`, devframe binds only `[::1]:\u003cport>`. Requests to `127.0.0.1:\u003cport>` then go to the other server.\n\nThe cause is in `get-port-please`, which devframe bundles. `getPort({ port, host })` tries to bind only the given host. `127.0.0.1` and `::1` can each hold the same port, so the port looks free. This is unjs/get-port-please#121, which is still open.\n\n`packages/devframe/src/node/instance-shell.ts` already notes that `getPort` can \"disagree across the v4/v6 duals of `localhost`\". The retry there runs only when the bind fails with `EADDRINUSE`. In this case the bind succeeds, so the retry does not run.\n\n### Versions\n\n- `devframe` 1.2.6 (`main` at `0e4a49c7`), `get-port-please` 3.2.0 (the latest release)\n- Linux: Node 22.23 in Docker `node:22-bookworm`, with IPv6 on the loopback interface\n- macOS 15: Node 22.22\n\n### Reproduction\n\n```js\nimport { createServer } from 'node:net'\nimport { defineDevframe } from 'devframe'\nimport { createDevServer } from 'devframe/adapters/dev'\n\nconst port = 19876\n\n// Another server holds the port on 127.0.0.1 only.\nconst other = createServer()\nawait new Promise(resolve => other.listen(port, '127.0.0.1', resolve))\n\nconst devframe = defineDevframe({ id: 'repro', name: 'Repro', cli: { port }, setup() {} })\nconst server = await createDevServer(devframe, { openBrowser: false })\n\nconsole.log(server.port) // Expected: a port other than 19876\n\nawait server.close()\nother.close()\n```\n\nThe script prints `19876` on Linux and on macOS.\n\nResults with another server on `127.0.0.1:\u003cport>`:\n\n| Platform | `host` | Conflict found | devframe binds |\n| --- | --- | --- | --- |\n| Linux, IPv6 on | `localhost` or not set | No | `[::1]:\u003cport>` |\n| Linux, IPv6 on | `0.0.0.0` | Yes | another port |\n| Linux, IPv6 off | any | Yes | another port |\n| macOS | `localhost` or not set | No | `[::1]:\u003cport>` |\n| macOS | `0.0.0.0` | No | `*:\u003cport>` |\n\nWhen the conflict is not found, `http://127.0.0.1:\u003cport>` reaches the other server. On Linux, Node `fetch('http://localhost:\u003cport>')` also reaches the other server. With `host: '0.0.0.0'` on macOS, `localhost` and `127.0.0.1` both reach the other server.\n\n### Proposed fix\n\nI have a fix with tests, and I can open a PR:\n\n1. In `get-port-please`, `getPort` also tries `127.0.0.1`, `::1`, `0.0.0.0` and `::` when the host is `localhost`, a loopback address, or a wildcard address. The port is in use if one of these binds fails with `EADDRINUSE` or `EACCES`. Other errors, such as `EADDRNOTAVAIL` when IPv6 is off, mean that the address does not exist. They do not count as \"in use\".\n2. devframe bundles `get-port-please`, so it carries the same change as a pnpm patch (`patches/get-port-please@3.2.0.patch`). The fix then reaches every caller of `devframe/utils/get-port`, for example Vite DevTools. You can remove the patch when upstream releases a fix.\n3. A regression test in `packages/devframe/src/adapters/__tests__/dev.test.ts`. It fails on `main` and passes with the patch, on Linux (IPv6 on) and on macOS.\n\nI will also send the same change upstream for unjs/get-port-please#121. If you want a different shape, tell me and I will change the PR. One option is a small wrapper in `devframe/utils/get-port` instead of a patch.\n","author":{"url":"https://github.com/DBAAZzz","@type":"Person","name":"DBAAZzz"},"datePublished":"2026-10-26T01:10:37Z","url":"https://github.com/devframes/devframe/issues/460"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5fa22405-19f3-1271-6988-9096bb04f562 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BF12:2781FE:950932:D17229:6AFB72C0 |
| html-safe-nonce | b030fe94ce0f93ee738da0a0b5c2d79c67368fe43299075b5a9a6895e05e3777 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjEyOjI3ODFGRTo5NTA5MzI6RDE3MjI5OjZBRkI3MkMwIiwidmlzaXRvcl9pZCI6IjkxNDUxMzU4Njc4Njg0NDMzMjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 467ea88c665316f8fe3d631792d45697ba99e0541efc3db9ad4613e0f2e18aea |
| hovercard-subject-tag | issue:6031499793 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/devframes/devframe/460/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d7b19ea07decac8487b2daeed976d961b43c258ae85bfa7bdbe4a121326ec6f6/devframes/devframe/issues/460 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d7b19ea07decac8487b2daeed976d961b43c258ae85bfa7bdbe4a121326ec6f6/devframes/devframe/issues/460 |
| og:image:alt | Summary If another server listens on 127.0.0.1: |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DBAAZzz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0e29e7974fdda2feeaf5c891efd4b23b0734b23480232b62c7bdef13f40b5b48 |
| turbo-cache-control | no-preview |
| go-import | github.com/devframes/devframe git https://github.com/devframes/devframe.git |
| octolytics-dimension-user_id | 279879373 |
| octolytics-dimension-user_login | devframes |
| octolytics-dimension-repository_id | 1231722386 |
| octolytics-dimension-repository_nwo | devframes/devframe |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1231722386 |
| octolytics-dimension-repository_network_root_nwo | devframes/devframe |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2e8872b770cc4d5d0cc1f2026afab747a268e2ce |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width