Skip to content

Cannot make a node-fetch request, TypeError: Cannot read property 'Symbol(requestOptions)' of undefined #36364

Description

@seven-deuce
  • Version: 14.15.1
  • Platform: MINGW64_NT-10.0-17763 DESKTOP-GJB54B0 3.0.7-338.x86_64 2019-04-30 21:52 UTC x86_64 Msys
  • Subsystem:

What steps will reproduce the bug?

Any call to foreign api, using a trusted library like "node-fetch", creates error and crash servers, on versions higher than 12.18
Here is the error:

_http_agent.js:444
      options = req[kRequestOptions];
                   ^

TypeError: Cannot read property 'Symbol(requestOptions)' of undefined
    at Agent.removeSocket (_http_agent.js:444:20)
    at TLSSocket.onClose (_http_agent.js:371:11)
    at TLSSocket.emit (events.js:327:22)
    at net.js:673:12
    at TCP.done (_tls_wrap.js:563:7)

How often does it reproduce? Is there a required condition?

All the time, not in version 12.18 or lower

What is the expected behavior?

a normal fetch, returning the result from any api, mostly a json

What do you see instead?

app crashes!

Additional information

Activity

  1. RaisinTen commented on Dec 3, 2020

    @RaisinTen
    Member

    I'm having some difficulty reproducing this:

    ❯ cat index.js
    const fetch = require('node-fetch');
    
    (async () => {
    	const response = await fetch('https://api.github.com/users/github');
    	const json = await response.json();
    
    	console.log(json);
    })();
    ❯ node index.js &> /dev/null
    ❯ echo $?
    0
    ❯ node -v
    v15.2.0
    ❯ uname -a
    Linux hp 4.15.0-124-generic #127-Ubuntu SMP Fri Nov 6 10:54:24 UTC 2020 i686 i686 i686 GNU/Linux

    As you can see, it exits with a zero error code.

  2. seven-deuce commented on Dec 4, 2020

    @seven-deuce
    Author

    I tracked down the issue and found out that one of the libs in the project, was defining methods on Object and Array Prototype.
    When I removed it, it all started to work,
    I wonder, what has changed after node v.12.18, that does not allow defining methods on Object/Array prototype??

  3. self-assigned this
    on Dec 6, 2020
  4. added
    httpIssues and PRs related to the http subsystem.
    on Dec 6, 2020
  5. removed their assignment
    on Dec 6, 2020
  6. Trott commented on Dec 9, 2020

    @Trott
    Member

    I tracked down the issue and found out that one of the libs in the project, was defining methods on Object and Array Prototype.
    When I removed it, it all started to work,
    I wonder, what has changed after node v.12.18, that does not allow defining methods on Object/Array prototype??

    This may be due to expanded use of what we call primordials on the project. The idea is that if a user changes the Object prototype, it should affect their code but not Node.js internal code. This is a security precaution but it may cause difficulty for people who "monkey-patch" Node.js internals like AMP vendors. I'd be curious to know what library is exhibiting this problem so we can track down whether this is expected breakage or a bug in Node.js that we need to fix.

  7. Trott commented on Dec 9, 2020

    @Trott
    Member

    I tracked down the issue and found out that one of the libs in the project, was defining methods on Object and Array Prototype.
    When I removed it, it all started to work,
    I wonder, what has changed after node v.12.18, that does not allow defining methods on Object/Array prototype??

    This may be due to expanded use of what we call primordials on the project. The idea is that if a user changes the Object prototype, it should affect their code but not Node.js internal code. This is a security precaution but it may cause difficulty for people who "monkey-patch" Node.js internals like AMP vendors. I'd be curious to know what library is exhibiting this problem so we can track down whether this is expected breakage or a bug in Node.js that we need to fix.

    Though it looks like @targos has already self-assigned this so they probably have a good idea what the bug is and what the fix is.

  8. targos commented on Dec 9, 2020

    @targos
    Member

    #36409 and #36410 are the pull requests that fix this issue. I referenced the issue in the PRs but forgot to do the opposite here, sorry!

  9. targos commented on Dec 9, 2020

    @targos
    Member

    To explain the bug: there was a semver-minor change that introduced a for ... in loop on the requests property of http Agent.
    If enumerable properties were added to Object.prototype, they would be iterated by this loop, triggering this bug because they probably wouldn't have an object at index 0.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues and PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions