Skip to content

lib: avoid mutating Error.stackTraceLimit when it is not writable - #38215

Merged
aduh95 merged 1 commit into
nodejs:masterfrom
aduh95:frozen-error
Apr 14, 2021
Merged

lib: avoid mutating Error.stackTraceLimit when it is not writable#38215
aduh95 merged 1 commit into
nodejs:masterfrom
aduh95:frozen-error

Conversation

@aduh95

Copy link
Copy Markdown
Contributor

This PR aims to avoid getting Cannot assign to read only property 'stackTraceLimit' of function 'function Error() { [native code] }' errors thrown from core when Node.js is executed with the --frozen-intrinsics flag.

@nodejs-github-botnodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 12, 2021
@aduh95aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 12, 2021
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment threadlib/assert.js Outdated

@bmeckbmeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized this should be checking configurable, not frozen status to handle if someone does an Object.seal(Error), etc.

@aduh95aduh95 removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 12, 2021
@aduh95

aduh95 commented Apr 13, 2021

Copy link
Copy Markdown
ContributorAuthor

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/998/

Results look OK-ish:

 confidence improvement accuracy (*) (**) (***)
misc/hidestackframes.js n=100000 type='direct-call-noerr' 0.02 % ±5.94% ±7.91% ±10.30%
misc/hidestackframes.js n=100000 type='direct-call-throw' * -2.86 % ±2.36% ±3.14% ±4.09%
misc/hidestackframes.js n=100000 type='hide-stackframes-noerr' 0.34 % ±15.71% ±20.91% ±27.25%
misc/hidestackframes.js n=100000 type='hide-stackframes-throw' -2.86 % ±3.23% ±4.30% ±5.60%

@aduh95aduh95 changed the title lib: avoid mutating Error.stackTraceLimit when Error is frozenlib: avoid mutating Error.stackTraceLimit when it is not writableApr 13, 2021
@aduh95
aduh95 requested a review from bmeckApril 13, 2021 10:44
Comment threadlib/internal/errors.js Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could try to cache the value when the property is not configurable:

Suggested change
returndesc.writable??typeofdesc.set==='function';
constreturnValue=desc.writable??typeofdesc.set==='function';
if(desc.configurable===false)
module.exports.isErrorStackTraceLimitWritable=()=>returnValue;
returnreturnValue;

I think it makes the harder to read, and I think we should try to optimize for the most common case (which is when the property has configurable and writable set to true).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine not cacheing for now

Comment threadlib/internal/errors.js Outdated
@aduh95
aduh95 requested a review from bmeckApril 13, 2021 14:27
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95

aduh95 commented Apr 13, 2021

Copy link
Copy Markdown
ContributorAuthor

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/999/

EDIT: the results are not as good… I'd say the tradeoff is worth it, I'm open to suggestions to improve those figures.

 confidence improvement accuracy (*) (**) (***)
misc/hidestackframes.js n=100000 type='direct-call-noerr' 2.68 % ±4.40% ±5.86% ±7.62%
misc/hidestackframes.js n=100000 type='direct-call-throw' ** -4.20 % ±3.04% ±4.05% ±5.29%
misc/hidestackframes.js n=100000 type='hide-stackframes-noerr' 13.07 % ±14.03% ±18.86% ±24.95%
misc/hidestackframes.js n=100000 type='hide-stackframes-throw' *** -4.70 % ±2.42% ±3.22% ±4.19%

Comment threadlib/internal/errors.js Outdated
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95

Copy link
Copy Markdown
ContributorAuthor

I've added more tests. I think this is ready to land but I'd love to get a final approval to make sure I haven't forgotten anything :)

@bmeckbmeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aduh95aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 14, 2021
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

PR-URL: nodejs#38215
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@aduh95

Copy link
Copy Markdown
ContributorAuthor

Landed in 09c9e5d

@aduh95
aduh95 merged commit 09c9e5d into nodejs:masterApr 14, 2021
@aduh95
aduh95 deleted the frozen-error branch April 14, 2021 22:18
BethGriggs pushed a commit that referenced this pull request Apr 15, 2021
PR-URL: #38215
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@aduh95@nodejs-github-bot@mscdex@bmeck@benjamingr@ExE-Boss@targos