Skip to content

os.networkInterfaces() can throw and crash the process when listening on 0.0.0.0 #7268

Done

Description

@defaultuser233

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

Activity

  1. defaultuser233 commented on Nov 26, 2026

    @defaultuser233
    ContributorAuthor

    复现验证(fastify 5.12.8,Node 24):

    Error: uv_interface_addresses returned Unknown system error 13
        at os.networkInterfaces (repro.mjs:7:23)
        at getAddresses (fastify/lib/server.js:365:29)
        at Object.logServerAddress (fastify/lib/server.js:382:19)
        at Server.listeningEventHandler (fastify/lib/server.js:290:32)
        at Server.wrapper (node:events:639:12)
    

    不带补丁时,await app.listen() 永不 resolve:异常抛在 listening 事件回调里,
    在 promise 链之外,try/catch 接不住,进程以未捕获异常退出。
    在测试里表现为整个测试文件挂住(199 秒后被超时杀掉),后续用例一个都没跑到。

    带上 getAddresses() 里的 catch 之后,同一个复现脚本正常打印 listening。

    修复已提 PR:#7270 —— getAddresses() 里 catch 住 os.networkInterfaces() 的异常并回退到
    绑定地址;新增用例在无修复时会失败并把整个测试文件带崩。

    另外补一条 Android 上的实测:官方 glibc 版 Node(nodejs.org v24.15.0 linux-arm64)在同一台
    设备上跑 require('os').networkInterfaces() 得到的是一模一样的
    uv_interface_addresses returned Unknown system error 13,所以这不是 Kimi Code 特有的问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions