Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

getPort ignores HOST, so a port in use on another interface forces a random PORT

未关闭 适合新手
#115 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
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
  1. Alias a second loopback address (macOS: sudo ifconfig lo0 alias 127.1.1.63).
  2. Occupy the port there: node -e "require('net').createServer().listen(3333, '127.1.1.63')"
  3. In an Adonis app: HOST=127.0.0.1 PORT=3333 NODE_DEBUG=adonisjs:core node ace test functional
  4. The debug line shows listening to utils http server, host :127.0.0.1, port: <random>, although 127.0.0.1:3333 is 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

adonisjs/assembler 的其他 Issue

查看 adonisjs/assembler 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。