getPort ignores HOST, so a port in use on another interface forces a random PORT
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 75/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
- 领域
- tooling
调研方向
从 dev server 和 node ace test 使用的 getPort() 入口点开始,跟踪 process.env.PORT 分支和从 .env 派生的分支。使用位于不同环回接口上的 HOST 和 PORT 进行复现,然后验证当配置的端口在该主机上空闲时仍会保留该端口,并确认相关的 assembler 测试通过。
由索引模型根据 Issue 内容生成。
描述
Package: @adonisjs/assembler (seen on 7.8.2, still present in 8.5.2) with get-port 7.1.0
What happens
getPort() (used by the dev server and node ace test) calls:
getRandomPort({ port: Number(process.env.PORT) }) // no host
Without a host, get-port treats the port as taken if it is in use on undefined, 0.0.0.0 or any local interface address. So if port 3333 is bound on 127.1.1.63, node ace test configured with HOST=127.1.1.62 PORT=3333 is handed a random free PORT, even though 127.1.1.62:3333 is free.
The app then listens on 127.1.1.62:<random>. Anything that derives its URL from the configured port — typically a BASE_URL for supertest/@japa/api-client in functional tests — points at 127.1.1.62:3333 and every request fails with ECONNREFUSED.
Reproduce
- Alias a second loopback address (macOS:
sudo ifconfig lo0 alias 127.1.1.63). - Occupy the port there:
node -e "require('net').createServer().listen(3333, '127.1.1.63')" - In an Adonis app:
HOST=127.0.0.1 PORT=3333 NODE_DEBUG=adonisjs:core node ace test functional - The debug line shows
listening to utils http server, host :127.0.0.1, port: <random>, although127.0.0.1:3333is free.
Why it matters
Running several checkouts' test suites side by side on one machine — each on its own loopback IP and the same port — is a natural way to parallelise. The run that starts last loses the race and fails every HTTP test, and nothing in the output says why.
Suggested fix
Pass the configured host through, so availability is checked where the server will actually bind:
getRandomPort({ port: Number(process.env.PORT), host: process.env.HOST })
(and the same for the .env-derived branch). When HOST is unset, behaviour stays as today.
- 主要语言
- TypeScript
- 星标
- 40
- 派生
- 24
- 平均合并
- 4 天 10 小时
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
adonisjs/assembler 的其他 Issue
-
Ctrl+C does not stop the dev server: raw mode suppresses SIGINT and close() never exits the process未关闭Status: Awaiting More Information
难度 4/5 3-5 天 新手友好度 58/100
-
难度 3/5 1-2 天 新手友好度 66/100
-
OpenAPI schema generation可能重新可做 @thetutlage 于 107 天前认领,目前没有进行中的 PR。 未关闭
查看 adonisjs/assembler 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
mobile-next/mobile-mcp#526 ·
维护者通常 1 天内回复
-
e2e-failure ready-to-code
难度 1/5 1 小时以内 新手友好度 73/100
redhat-developer/rhdh-plugin-export-overlays#4470 · 1 条评论 ·
维护者通常 1 天内回复