undici icon indicating copy to clipboard operation
undici copied to clipboard

onConnectTimeout bug

Open zabranskiy opened this issue 1 year ago • 1 comments

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

zabranskiy avatar Oct 21 '24 12:10 zabranskiy

#3751

KhafraDev avatar Oct 21 '24 14:10 KhafraDev

+1 Is there a solution?

murrayee avatar Nov 03 '24 17:11 murrayee

or how do I catch it?

murrayee avatar Nov 03 '24 17:11 murrayee

@murrayee do you have a reproducible sample of code?

KhafraDev avatar Nov 03 '24 19:11 KhafraDev

Faced the same issue. Created a MR.

SolT31 avatar Nov 12 '24 13:11 SolT31