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 property 'asyncReset' of null #13539

Closed
zkd8907 opened this issue Jun 8, 2017 · 16 comments · Fixed by #14419
Closed

Cannot read property 'asyncReset' of null #13539

zkd8907 opened this issue Jun 8, 2017 · 16 comments · Fixed by #14419
Labels
async_hooks Issues and PRs related to the async hooks subsystem. http Issues or PRs related to the http subsystem.

Comments

@zkd8907
Copy link

zkd8907 commented Jun 8, 2017

  • Version: 8.0.0
  • Platform: Linux x64

We deployed Node 8.0 on our servers, but found an error when a large number of concurrent requests came.

Stack:

TypeError: Cannot read property 'asyncReset' of null
    at Agent.addRequest (_http_agent.js:170:19)
    at new ClientRequest (_http_client.js:271:16)
    at Object.request (http.js:39:10)

I checked the source file _http_agent.js. Line 170 is socket._handle.asyncReset();. I think it's better to check whehter socket._handle is null before use.

@AndreasMadsen AndreasMadsen added async_hooks Issues and PRs related to the async hooks subsystem. http Issues or PRs related to the http subsystem. labels Jun 8, 2017
@AndreasMadsen
Copy link
Member

You are most likely using a custom agent somewhere in your code. Any change you could check for that? We would always like to understand the cause of the error, rather than just making a blind fix. Preventing asyncReset() from being called by checking socket._handle may cause other issues.

/cc @nodejs/async_hooks

@trevnorris
Copy link
Contributor

@AndreasMadsen Unfortunately I haven't found a better approach than to check if socket._handle exists in the case of passing a custom Agent. We have to do something similar in lib/timers.js because custom timer objects can be passed in (and we do that quite a bit in core)`.

Though we may be able to get around this using a combination of my final proposal at the bottom of #13548 (comment) and what we do in lib/timers.js. Which is we assign a new asyncId to the custom object on async_id_symbol and use that. It may have a strange timing issue about when to run init() but I think that's something we can get around.

@mnutt
Copy link

mnutt commented Jul 2, 2017

I'm seeing the same error, while using an instantiated agent:

const agent = new http.Agent({
  keepAlive: true,
  maxSockets: 128,
  maxFreeSockets: 64
});

http.request({agent, ....});

Would we see a difference in this approach vs just modifying the limits of the default global agent?

@refack
Copy link
Contributor

refack commented Jul 2, 2017

I'm seeing the same error, while using an instantiated agent:

@mnutt we've been rolling patches around this area during the last month (#13348, #13092, and soon #14026 and #13839). Are you still seeing this error in node@8.1.3?

@mnutt
Copy link

mnutt commented Jul 3, 2017

Sorry, I should have mentioned that yes, it was node 8.1.3.

@adiulici
Copy link

adiulici commented Jul 17, 2017

I'm seeing the same issue on node v8.1.14. Unfortunately it's being thrown inside a dependency (new relic) so I cannot offer much of a detail.

@AndreasMadsen
Copy link
Member

@aashil could you try the nightly build, most of the async_hooks fixes are in v8.2.0 which hasn't been released yet (#13744).

@adiulici
Copy link

@AndreasMadsen Unfortunately I only see this on my production environment when the number of concurrent users is high, and I can't put a nightly build on it..

@refack
Copy link
Contributor

refack commented Jul 19, 2017

@adiulici node@8.2.0 was just released some relevant bug fixes are in it. If you are comfortable you could try it.

@rwlaschin
Copy link

HI. I'm seeing this issue as well 8.1.4

I'm using a custom agent
const keepAliveAgent = new http.Agent({ keepAlive: true });

I'll try 8.2.0 and see if the issue is resolved.

@rwlaschin
Copy link

rwlaschin commented Jul 20, 2017

Unfortunately, no it still happens

2017-07-20T11:31:56-0700 <error> RouteLoader.js:60 () message Cannot read property 'asyncReset' of null error TypeError: Cannot read property 'asyncReset' of null
    at Agent.addRequest (_http_agent.js:171:19)
    at new ClientRequest (_http_client.js:272:16)
    at Object.request (http.js:39:10)
    at Request.send (/Users/robert/Repositories/ry-openrtb-exchange/rtbexchange/server/modules/Bid/Request.js:88:11)
    at /Users/robert/Repositories/ry-openrtb-exchange/rtbexchange/server/modules/Dsp/Manager.js:172:29
    at Utilities.ProcessorRunner.completefn (/Users/robert/Repositories/ry-openrtb-exchange/rtbexchange/server/interfaces/Utilities.js:147:9)
    at /Users/robert/Repositories/ry-openrtb-exchange/rtbexchange/node_modules/async/internal/once.js:12:16
    at iteratorCallback (/Users/robert/Repositories/ry-openrtb-exchange/rtbexchange/node_modules/async/eachOf.js:60:13)
    at /Users/robert/Repositories/ry-openrtb-exchange/rtbexchange/node_modules/async/internal/onlyOnce.js:12:16

It is very frequent.

edit trevnorris: place output in code block

@rwlaschin
Copy link

I did not see it when I changed back to version 7.10.1, it was in all the versions of 8.. that I tried.

I don't believe I saw this error until I added node-redis, I'm not sure if that is a red-herring or not.

@trevnorris
Copy link
Contributor

Sorry for the delay. See the issue. I'll write up a fix tonight.

@refack
Copy link
Contributor

refack commented Jul 21, 2017

I did not see it when I changed back to version 7.10.1, it was in all the versions of 8.. that I tried.

I don't believe I saw this error until I added node-redis, I'm not sure if that is a red-herring or not.

So for context: node v8 added a new layer of tracing (i.e. Async Hooks). This layer is active even if the user does not use it, to enable ad hoc interrogating the system state.
Although this new layer has been meticulously designed and tested, there are a few open edge cases (one of them is custom implementations of HTTP Agent).
node@8.2.0 included several bug fixes in this layer (node@8.2.1 was fast tracked, and we managed to release it 1 day after 8.2.0 to solve two new bugs in Async Hooks). Meanwhile we converged on a design change that should minimize (hopefully eliminate) errors experienced by users who don't actually activate the Async Hooks.
Thank you for your patience, and your support by reporting these issues! 🎩

@trevnorris
Copy link
Contributor

Fix at #14419.

refack pushed a commit to trevnorris/node that referenced this issue Jul 25, 2017
If an uninitialized or user supplied Socket is in the freeSockets list
of the Agent it would automatically attempt to run
._handle.asyncReset(), but would throw from those not existing. Guard
against that by first checking that they exist.

PR-URL: nodejs#14419
Fixes: nodejs#13539
Refs: nodejs#13352
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
addaleax pushed a commit that referenced this issue Jul 27, 2017
If an uninitialized or user supplied Socket is in the freeSockets list
of the Agent it would automatically attempt to run
._handle.asyncReset(), but would throw from those not existing. Guard
against that by first checking that they exist.

PR-URL: #14419
Fixes: #13539
Refs: #13352
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
avwo added a commit to avwo/whistle that referenced this issue Jul 31, 2017
avwo added a commit to avwo/whistle that referenced this issue Jul 31, 2017
@SoumyaDey1994
Copy link

Hi,

Is there any workaround to ignore this issue in version 8.1.x? Our production environment is having version 8.1.x and migrating it to a higher version may cause other implications in our codebase.

Please suggest a remedy for version 8.1.x. Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants