-
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
Modifying error.message
does not update error.stack
if stream.destroy(error)
has been called
#51715
Comments
Shouldn't it be reported to V8 instead? |
It seems to be working correctly on Chrome |
Chrome does not have
The bug is that Node.js has the following line inside node/lib/internal/streams/destroy.js Lines 33 to 35 in 8a41d9b
This workaround was meant for the unit tests, but it is creating user-facing problems. |
I don't think it works in Chrome. err = Error('foo')
err.stack
err.message = `bar ${err.message}`
console.log(err)
I think it is a bug in V8 because the memorization of stack trace variables leads to the user cannot properly cache or recycle the error when it dispose (it is the cause of memory leak). The problem it tends to stop is not only related to the test case, but also the user environment. If the trick |
Memoizing The bug being reported relates to the Node.js stream API, in particular What can be fixed though is the workaround highlighted in my initial message. It appears that this workaround was intended to fix some automated tests, but it unfortunately creates user-facing issues. |
If the memory leak exists in test, which means it will also happen in user code. If the memory leak did not pop up in first place, there is no need of workaround. |
Yes, that's a good point about this not being only an issue with the automated tests, but a memory leak which could potentially be experienced by users too.
The V8 implementation might introduce a memory leak per @addaleax comment:
However, if this is the case, it is unclear how many years for this bug to be solved. It is also unclear to me whether the v8 team would agree that this is a bug. As mentioned by @addaleax:
The approach in #34103 has not been to wait for the potential V8 bug to be fixed, but instead of find a workaround right away. That workaround has a problem which (I think) might not have been anticipated based on @addaleax comment:
Beyond the small performance penalty, this workaround introduces a bigger problem: modifying I am curious whether a different workaround exists that would not have this side effect. 🤔 |
Version
v21.1.0
Platform
Linux ether-laptop 6.5.0-15-generic #15-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 9 17:03:36 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
No.
What is the expected behavior? Why is that the expected behavior?
Printed error should show "Additional info".
What do you see instead?
Printed error does not show "Additional info".
Additional information
This is due to #34103, specifically this:
As implemented in:
node/lib/internal/streams/destroy.js
Line 35 in 8a41d9b
If
error.message
is modified later on (e.g. due to prepending some additional information), the change won't be reflected witherror.stack
. This is unfortunate becauseerror.stack
is used byutil.inspect()
, which is itself used byconsole.log()
.The text was updated successfully, but these errors were encountered: