-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Error.stackTraceLimit
becomes undefined
when running from snapshot
#55100
Comments
We are currently manually deleting node/lib/internal/main/mksnapshot.js Lines 149 to 159 in f29d2b7
Some background on this behavior: when V8 deserialize the snapshot, it will try to re-install
It does seems strange though why the limit isn't re-initialized to 10 (the default of |
So V8 doesn't actually install
3 would be the easiest, I am skeptical whether 1 would actually be accepted by the upstream. |
2 (specifically the stackTraceLimit, not webassembly) sounds good to me. If there aren't security concerns about having stack traces enabled by default during the snapshot building. This feels user friendly for getting started with snapshots. 3 also sounds good if 2 isn't viable. |
When V8 creates a context for snapshot building, it does not install Error.stackTraceLimit. As a result, error.stack would be undefined in the snapshot builder script unless users explicitly initialize Error.stackTraceLimit, which may be surprising. This patch initializes Error.stackTraceLimit based on the value of --stack-trace-limit to prevent the surprise. If users have modified Error.stackTraceLimit in the builder script, the modified value would be restored during deserialization. Otherwise, the fixed up limit would be deleted since V8 expects to find it unset and re-initialize it during snapshot deserialization. PR-URL: #55121 Fixes: #55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Previously, --trace-exit and --trace-sync-io doesn't take care of --stack-trace-limit and always print a stack trace with maximum size of 10. This patch parses --stack-trace-limit during initialization and use the value in --trace-* flags. PR-URL: #55121 Fixes: #55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
When V8 creates a context for snapshot building, it does not install Error.stackTraceLimit. As a result, error.stack would be undefined in the snapshot builder script unless users explicitly initialize Error.stackTraceLimit, which may be surprising. This patch initializes Error.stackTraceLimit based on the value of --stack-trace-limit to prevent the surprise. If users have modified Error.stackTraceLimit in the builder script, the modified value would be restored during deserialization. Otherwise, the fixed up limit would be deleted since V8 expects to find it unset and re-initialize it during snapshot deserialization. PR-URL: #55121 Fixes: #55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Previously, --trace-exit and --trace-sync-io doesn't take care of --stack-trace-limit and always print a stack trace with maximum size of 10. This patch parses --stack-trace-limit during initialization and use the value in --trace-* flags. PR-URL: #55121 Fixes: #55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
When V8 creates a context for snapshot building, it does not install Error.stackTraceLimit. As a result, error.stack would be undefined in the snapshot builder script unless users explicitly initialize Error.stackTraceLimit, which may be surprising. This patch initializes Error.stackTraceLimit based on the value of --stack-trace-limit to prevent the surprise. If users have modified Error.stackTraceLimit in the builder script, the modified value would be restored during deserialization. Otherwise, the fixed up limit would be deleted since V8 expects to find it unset and re-initialize it during snapshot deserialization. PR-URL: #55121 Fixes: #55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Previously, --trace-exit and --trace-sync-io doesn't take care of --stack-trace-limit and always print a stack trace with maximum size of 10. This patch parses --stack-trace-limit during initialization and use the value in --trace-* flags. PR-URL: nodejs#55121 Fixes: nodejs#55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
When V8 creates a context for snapshot building, it does not install Error.stackTraceLimit. As a result, error.stack would be undefined in the snapshot builder script unless users explicitly initialize Error.stackTraceLimit, which may be surprising. This patch initializes Error.stackTraceLimit based on the value of --stack-trace-limit to prevent the surprise. If users have modified Error.stackTraceLimit in the builder script, the modified value would be restored during deserialization. Otherwise, the fixed up limit would be deleted since V8 expects to find it unset and re-initialize it during snapshot deserialization. PR-URL: nodejs#55121 Fixes: nodejs#55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Previously, --trace-exit and --trace-sync-io doesn't take care of --stack-trace-limit and always print a stack trace with maximum size of 10. This patch parses --stack-trace-limit during initialization and use the value in --trace-* flags. PR-URL: nodejs#55121 Fixes: nodejs#55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
When V8 creates a context for snapshot building, it does not install Error.stackTraceLimit. As a result, error.stack would be undefined in the snapshot builder script unless users explicitly initialize Error.stackTraceLimit, which may be surprising. This patch initializes Error.stackTraceLimit based on the value of --stack-trace-limit to prevent the surprise. If users have modified Error.stackTraceLimit in the builder script, the modified value would be restored during deserialization. Otherwise, the fixed up limit would be deleted since V8 expects to find it unset and re-initialize it during snapshot deserialization. PR-URL: nodejs#55121 Fixes: nodejs#55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Version
v22.8.0
Platform
Subsystem
No response
What steps will reproduce the bug?
Description
Error.stackTraceLimit
isundefined
while the snapshot is being run, meaning code which "resets"stackTraceLimit
after temporarily modifying it is consequently setting it toundefined
which is persisted when resuming from the snapshot.I hit this when importing
typescript
while building the snapshot.Setup
Create this file:
No snapshots:
> node app.js warmup: Error.stackTraceLimit is 10 task: typeof err.stack is string
With snapshots:
How often does it reproduce? Is there a required condition?
100%
What is the expected behavior? Why is that the expected behavior?
I was expecting
Error.stackTraceLimit
to have the same starting value regardless of if--build-snapshot
is passed.As a result I was also expecting
error.stack
withintask
to be defined when running from the snapshot, because it is defined when running without the snapshot.What do you see instead?
Error.stackTraceLimit
isundefined
when running with--build-snapshot
.As a result
typeof error.stack
isstring
when running the code normally andundefined
when using a snapshot.Additional information
Startup snapshots parent issue: #44014
error.stack
beingundefined
while building the snapshot - I presume this is there as a security precaution to avoid leaking implementation details of the file system into the snapshot? Maybe this could be documented? (apologies if this is already the case)I wonder if the logic for restoring
Error.stackTraceLimit
should only happen if the snapshot builder explicitly setsError.stackTraceLimit
to a number and not toundefined
- becauseundefined
is the starting state it hasn't actually been changed by the snapshot builder.The workaround I have in place is to explicitly set
Error.stackTraceLimit = 10;
before exiting the snapshot builder. This works, however it would be nice to not hard-code the size and instead allow it to retain the default. EDIT:delete Error.stackTraceLimit;
at the end of the snapshot building seems to be a 'better' workaround.The text was updated successfully, but these errors were encountered: