Skip to content

T-010: fix: respect HOST when selecting port - #126

Merged
thetutlage merged 2 commits into
8.xfrom
task/T-010
Nov 16, 2026
Merged

thetutlage merged 2 commits into
8.xfrom
task/T-010

Conversation

@fleet-panda

@fleet-panda fleet-panda Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #124 by @joniilmanfahmi00-collab

Closes #115

Goal

getPort() of @adonisjs/assembler, which the dev server and node ace test use, checks if the port is free on the host where the app will listen.

The pull request #124 passes HOST only from the place where it found PORT. The app reads HOST from process.env first and then from the .env files. This pull request makes getPort() read HOST the same way, apart from where PORT comes from. The commit of the contributor stays.

Deployment requirements

  • Release @adonisjs/assembler as a patch.

Acceptance criteria

All tests are in tests/utils/get_port.spec.ts. npm run lint, npm run typecheck and npm run quick:test (305 tests) pass.

  • getPort() resolves HOST from process.env first, then from the .env files, in the order the app reads them, and passes it to get-port.
    • Tests: give preference to HOST from process.env over .env file, give preference to HOST from .env.local file over .env file. Pass.
  • It does so in each of its three cases: PORT from process.env, PORT from a .env file, and the default port 3333.
    • Tests: pass HOST from process.env to get-port, pass HOST from .env file to get-port, pass HOST to get-port when using the default port 3333. Pass.
  • With HOST in process.env and PORT in .env, and the reverse, the port is checked on that HOST.
    • Tests: pass HOST from process.env when PORT comes from .env file, pass HOST from .env file when PORT comes from process.env. Pass.
  • When HOST is not set anywhere, get-port gets no host, as today.
    • Test: check the port on all the local hosts when HOST is not set. Pass.

Four of the new tests fail on the code of #124: the default port 3333, HOST and PORT from different places, and .env.local over .env.

Decisions about the code

  • getPort() now loads and parses each .env file each time, also when process.env.PORT is set. HOST can be in a .env file when PORT is not.
  • An empty HOST counts as not set, the same way an empty PORT does today.
  • getPort() passes no host key to get-port when HOST is not set, so get-port keeps its check on each local host.
  • The tests call clearLockedPorts() of get-port before each test, because get-port locks each port that it gives for 15 seconds.

Context changes

None.

Discovered work

  • TestRunner.runAndWatch() in src/test_runner.ts sets #stickyHmrPort with String(getRandomPort({ port: 24678 })) and no await. The value is [object Promise]. TestRunner.run() has the await.

syifanazilah-afk and others added 2 commits November 5, 2026 13:07
getPort() now resolves PORT and HOST separately, each from process.env
first and then from the dot-env files in their order of priority. The
port is checked on HOST in each case, including the default port 3333.

Closes #115
@thetutlage
thetutlage merged commit d83a76e into 8.x Nov 16, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants