Skip to content

req.socket might be null #42

Closed
Closed

Description

@Gerhut

See discussion in nodejs/undici#1115, nodejs/node#41011.

There will be TypeError: Cannot read properties of null (reading 'destroy') when using req as body in undici.stream, which sets req.socket to null.

Activity

  1. dougwilson commented on Jul 4, 2022

    @dougwilson
    Contributor

    Thanks for reporting, @Gerhut ! I do indeed see the Node.js docs have updated to note that req.socket is no longer guaranteed to be there, and that there is a code path within Node.js itself that now unsets it. I will get a patch out for this module to account for this new behavior.

  2. self-assigned this
    on Jul 4, 2022
  3. dougwilson commented on Jul 13, 2022

    @dougwilson
    Contributor

    Sorry for the delay on this. It seems very convoluted on when exactly Node.js will make req.socket null. I see that there is a guard against that in req.destroy(), though not a lot of other methods on req. I believe we can just call req.destroy() anyway, just verifying that will behave as expected across the supported Node.js versions of this module before landing, as it would be the simplest solution 👍

  4. blazzy commented on Jun 21, 2023

    @blazzy

    @dougwilson Any luck with this? I'm running into an occasional error where req.socket is null and req.socket.destroy ends up blowing up.
    Undici in particular is clearing out the socket when we stream a request through it and the connection is suddenly killed.

  5. wesleytodd commented on Sep 1, 2024

    @wesleytodd
    Member

    Just opened #57 with a fix for this. Planning on releasing it in the current major and then pulling it into express asap. Moving any discussion over there now.

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

Metadata

Metadata

Assignees

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