Jeff-Lewis / cls-hooked

cls-hooked : CLS using AsynWrap or async_hooks instead of async-listener for node 4.7+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Busy server hits RangeError

jason-codaio opened this issue · comments

I've notice during some active payloads we are generating a large number of async promises which ends up filling up the context map here:

https://github.com/Jeff-Lewis/cls-hooked/blob/master/context.js#L316

This happens after the Map has 16777216 entries and it throws a RangeError when you try to insert another. I've confirmed the hooks are not leaking as they are in the node queue to be destroyed its just that garbage collection has not been called yet.....

Any thoughts on how to mitigate or more gracefully fall back?

I'm going to close this out, but I wanted to summarize what I found. Basically we were CPU locking the main thread despite awaiting 16M+ async functions. I added a smartly placed setImmediate into our event loop and the problem has gone away as we make sure we give the garbage collector time to run.

We apparently had this time bomb since we migrated from Bluebird promises to native promises.