Skip to content

build_backtrace called too often on stack unwinding #904

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

Closed
bnoordhuis opened this issue Feb 10, 2025 · 1 comment · Fixed by #906
Closed

build_backtrace called too often on stack unwinding #904

bnoordhuis opened this issue Feb 10, 2025 · 1 comment · Fixed by #906
Labels
bug Something isn't working

Comments

@bnoordhuis
Copy link
Contributor

function f() { f() }
let count = 0
Error.prepareStackTrace = () => count++
try {
    f()
} catch (e) {
    // ignore
}
print(count) // prints ~157, increases with bigger --stack-size

It's due to the build_backtrace call in JS_CallInternal that's called every time a stack frame is unwound.

Another way of demonstrating the issue:

function f(n) {
    if (--n > 0) f(n)
    else throw Error("unwind")
}
Error.prepareStackTrace = (exc, stk) => print(stk.length)
try {
    f(16)
} catch (e) {
    // ignore
}

Prints:

10
10
10
10
10
10
10
10
10
9
8
7
6
5
4
3
2
1
@bnoordhuis bnoordhuis added the bug Something isn't working label Feb 10, 2025
@bnoordhuis
Copy link
Contributor Author

Looks to have been introduced in 4c32c53, mea culpa.

bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Feb 10, 2025
Bug introduced in commit 4c32c53 from late last month.

When unwinding the stack, call build_backtrace only when the exception
object doesn't already have a .stack property, like how it was before
commit 4c32c53.

Fixes: quickjs-ng#904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant