Skip to content

onConnectTimeout bug #3752

@zabranskiy

Description

@zabranskiy

Bug Description

[error] uncaughtException TypeError: Cannot read properties of undefined (reading 'autoSelectFamilyAttemptedAddresses') at onConnectTimeout (/usr/lib/node_modules/.../node_modules/undici/lib/core/connect.js:224:28) at Immediate.<anonymous> (/usr/lib/node_modules/.../node_modules/undici/lib/core/connect.js:206:11) at process.processImmediate (node:internal/timers:491:21)

undici/lib/core/connect.js file has function onConnectTimeout:

function onConnectTimeout (socket, opts) {
  let message = 'Connect Timeout Error'
  if (Array.isArray(socket.autoSelectFamilyAttemptedAddresses)) { <-- bug in this line
  ...
}

socket is undefined when the garbage collector has already freed the WeakRef, which leads to TypeError.

Reproducible By

It happens rarely on our prod.

Expected Behavior

No error.

Environment

Debian 12
nodejs 22.9.0
undici 6.20.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions