Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#115 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu từ điểm vào getPort() được dev server và node ace test sử dụng, theo dõi cả nhánh process.env.PORT lẫn nhánh được suy ra từ .env. Tái hiện với HOST và PORT trên các giao diện loopback riêng biệt, sau đó xác minh rằng cổng được cấu hình vẫn được giữ lại khi còn trống trên host đó và các bài kiểm thử assembler liên quan đều đạt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
40
Fork
24
Merge trung bình
10 ngày 22 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của adonisjs/assembler

Tất cả issue của adonisjs/assembler

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.