Skip to content

test: fix test when localhost has multiple addresses#6427

Merged
mcollina merged 1 commit intofastify:mainfrom
LiviaMedeiros:test-listen-multilocal
Dec 28, 2025
Merged

test: fix test when localhost has multiple addresses#6427
mcollina merged 1 commit intofastify:mainfrom
LiviaMedeiros:test-listen-multilocal

Conversation

@LiviaMedeiros
Copy link
Copy Markdown
Contributor

This PR assumes that sorting in algorithm introduced in #5476 works as intended, and fastify.listen({ host: '0.0.0.0' }) is not obligated to return 127.0.0.1 when system has other localhost addresses.

Relevant function:

fastify/lib/server.js

Lines 363 to 374 in 5317c90

function getAddresses (address) {
if (address.address === '0.0.0.0') {
return Object.values(os.networkInterfaces()).flatMap((iface) => {
return iface.filter((iface) => iface.family === 'IPv4')
}).sort((iface) => {
/* c8 ignore next 2 */
// Order the interfaces so that internal ones come first
return iface.internal ? -1 : 1
}).map((iface) => { return iface.address })
}
return [address.address]
}

Checklist

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 270d367 into fastify:main Dec 28, 2025
30 checks passed
@github-actions
Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants