Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#115 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
tooling

Direzione di ricerca

Inizia dal punto di ingresso getPort() utilizzato dal server di sviluppo e da node ace test, tracciando sia il ramo process.env.PORT sia quello derivato da .env. Riproduci il problema con HOST e PORT su interfacce loopback separate, quindi verifica che la porta configurata venga mantenuta quando è libera su quell’host e che i test assembler pertinenti passino.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
40
Fork
24
Merge medio
10g 22h
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di adonisjs/assembler

Tutte le issue di adonisjs/assembler

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.