os.networkInterfaces() can throw and crash the process when listening on 0.0.0.0
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
- Domain
- backend, networking
Research direction
Start in lib/server.js at getAddresses() and trace how logServerAddress() handles the addresses returned for a wildcard bind. Reproduce the failure by making os.networkInterfaces() throw, then check the server tests for address logging and add coverage for the fallback. Done means the server starts and reports the bound address when interface enumeration fails.
Written by the indexing model from the issue text.
Description
Describe the bug
When the server binds to the wildcard address 0.0.0.0, logServerAddress() calls getAddresses(), which calls os.networkInterfaces() unguarded. On platforms where enumerating the interface list is not permitted, os.networkInterfaces() throws, and because the call happens inside the server's listening event handler the exception escapes as an uncaught exception — the process dies instead of the server starting.
Concrete case: Android. A Node.js binary linked against glibc (e.g. a single-executable build) calls getifaddrs(), which needs CAP_NET_ADMIN for its NETLINK_ROUTE RTM_GETLINK dump and also reads /proc/net/if_inet6. Android denies both to ordinary apps, so getifaddrs() returns EACCES and Node throws:
SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_interface_addresses returned Unknown system error 13 (Unknown system error 13)
at Object.networkInterfaces (node:os:218:16)
at getAddresses (/path/to/fastify/lib/server.js:...)
at Object.logServerAddress (/path/to/fastify/lib/server.js:...)
at Server.listeningEventHandler (/path/to/fastify/lib/server.js:...)
The same crash happens in any sandbox/container that forbids reading the interface list, not only Android. Note that binding to a specific address is unaffected — getAddresses() only calls os.networkInterfaces() for the 0.0.0.0 case.
Steps to reproduce
// repro.mjs
import os from 'node:os'
import Fastify from 'fastify'
// Stand in for a platform where interface enumeration is denied.
// (On Android this happens for real, see the stack trace above.)
const real = os.networkInterfaces
os.networkInterfaces = () => {
throw Object.assign(new Error('uv_interface_addresses returned Unknown system error 13'), {
code: 'ERR_SYSTEM_ERROR',
})
}
const app = Fastify()
app.get('/', async () => 'hello')
await app.listen({ host: '0.0.0.0', port: 0 })
console.log('listening')
The await never settles: the exception is thrown in the listening event handler, so it is reported as an uncaught exception and the process exits with a non-zero code, instead of the server starting.
Expected behavior
Failing to enumerate the interface list should not be fatal. The server should still start, and the address list should fall back to the bound address (as it already does for a non-wildcard bind).
Suggested fix
Guard the call in getAddresses() and fall back to the bound address:
function getAddresses (address) {
if (address.address === '0.0.0.0') {
let interfaces
try {
interfaces = os.networkInterfaces()
} catch {
return [address.address]
}
return Object.values(interfaces).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]
}
System Info
- fastify version: 5.8.5
- Node.js version: v24.15.0
- Platform: Android 12 (aarch64), Node linked against glibc
- Dominant language
- JavaScript
- Stars
- 37.5k
- Forks
- 3.2k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 22
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fastify/fastify
-
Document using preClose to stop starting new plugin work during shutdownPossibly taken @lazerg claimed this 49 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
fastify/fastify#7083 · 4 comments ·
Maintainers usually reply within 1 day
-
docs(Getting-Started): Install section only documents npm and yarnPossibly taken @Shreya657 claimed this 85 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 94/100
fastify/fastify#6983 · 1 comment ·
Maintainers usually reply within 1 day
-
`path` alias missing from RouteOptions typePossibly taken @veeceey claimed this 285 days ago. Opentypescript
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
fastify/fastify#6012 · 10 comments ·
Maintainers usually reply within 1 day
-
Using $ref in response work really strange/not at allPossibly taken @mcollina claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 20/100
Maintainers usually reply within 1 day
-
Null entry in schema content map crashes startup with TypeError instead of FST_ERR_SCH_CONTENT_MISSING_SCHEMAPossibly taken @Ganesh1729-ui claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
Maintainers usually reply within 1 day
Similar issues
-
FEATURE REQUEST
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
linuxmint/cinnamon-spices-applets#9356 ·
Maintainers usually reply within 1 day
-
needs-triage Platform(Default)
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
linagora/twake-drive#4659 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day