Skip to content

Cannot read properties of null (reading 'destroyed') #2704

@ktaekwon000

Description

@ktaekwon000

Bug Description

Very occasionally, undici will throw this error as an uncaught rejection, causing the node process to crash.
The stack trace is as follows:

TypeError: Cannot read properties of null (reading 'destroyed')
    at _resume (/node_modules/undici/lib/client.js:1429:16)
    at resume (/node_modules/undici/lib/client.js:1334:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:81:21)

Reproducible By

I am unable to replicate this issue consistently, but this issue pops up frequently, sometimes multiple times in a week.

Environment

Debian 12.4, node v18.19.0, undici 6.5.0

Additional context

    if (!socket && !client[kHTTP2Session]) {
      connect(client)
      return
    }

    if (socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking]) {
      return
    }

The error occurs in the condition of the second if clause, where socket is null. I believe that

  1. client[kHTTP2Session] is not being set to null on socket close, despite socket being set to null. I see another function in client.js, onUpgrade, where socket is being set to null but client[kHTTP2Session] is not touched, but I believe this should not be called when client[kHTTP2Session] is truthy.
  2. Perhaps first if clause should be rolled back to if (!socket) { to account for null socket even if client[kHTTP2Session] is truthy, so that http2 connect logic is triggered if socket is null. I'm not entirely sure of the reason this if clause was changed.

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