Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ktaekwon000 opened this issue Feb 6, 2024 · 2 comments · Fixed by #2711
Closed

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

ktaekwon000 opened this issue Feb 6, 2024 · 2 comments · Fixed by #2711
Labels
bug Something isn't working

Comments

@ktaekwon000
Copy link

ktaekwon000 commented Feb 6, 2024

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.
@ktaekwon000 ktaekwon000 added the bug Something isn't working label Feb 6, 2024
@metcoder95
Copy link
Member

Hmm, good catch; the HTTP2Session depends on the socket, one cannot exist without the other; matter of fact there are several places that might need to be refactored better to account for the mix of the HTTP2 session and socket.

Do you think you can provide an
Minimum Reproducible Example to reproduce your problem? I know you said might be hard, but something we can run to debug it (doesn't matter it only works the nth time)

@ktaekwon000
Copy link
Author

I suspect that an environment that drops TCP connections randomly could cause this error, but I've tried and failed to write a MRE for it 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants