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
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
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
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.

2 participants