-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
performance.getEntries and performance.getEntriesByName cause call stack size to be exceeded #54768
Comments
cc @nodejs/primordials |
That's a good risk to document of ArrayPrototypePushApply. |
I'll open a PR to fix this though I'm not sure how to test this (i.e. it tests internal implementation detail of V8 rather than a JavaScript behavior and I'm hesitant to add an explicit test since it tests that but I'll do what people thing). |
It’s not, it takes exactly two arguments. |
The error can be reproduced by running |
yes, argument lists are limited to 2^32 - 1 items, i believe. |
Version
v18.14.0 - v22.7.0
Platform
Subsystem
perf_hooks
What steps will reproduce the bug?
Executing this script:
How often does it reproduce? Is there a required condition?
100% of the time
What is the expected behavior? Why is that the expected behavior?
The expected behaviour is that the script completes successfully given the number of performance entries at any time is below the established warning threshold:
What do you see instead?
With the default stack size of 984kB the script consistently fails at an order of magnitude lower than the established warning threshold:
Additional information
This bug appears to have been introduced in v18.14.0 when #44445 added a usage of the ArrayPrototypePushApply primordial in filterBufferMapByNameAndType as part of an effort to eliminate usages of
ArrayPrototypeConcat
.ArrayPrototypePushApply
is a variadic function, which appears to be problematic in this instance because it’s being called with each element in the buffer of performance entries - each passed as individual arguments. The size of the performance entries buffer is effectively unbounded, so at scale the underlyingArray.prototype.push
method is being called with an unbounded number of arguments resulting in massive stack frames which cause the maximum call stack size to be exceeded.If this is, as it appears, to be a general risk with the usage of variadic primordials with unbounded argument lists it may at least be worth a callout in the primordials documentation on variadic functions.
The text was updated successfully, but these errors were encountered: