Skip to content
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

Experiment: AsyncPromise, a Promise that captures 1 stack frame #11948

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Jarred-Sumner
Copy link
Collaborator

What does this PR do?

Stack traces for async functions are often missing

This adds an internal Promise wrapper for async native functions which captures 1 stack frame and propagates it on promise rejection.

After:

 9 | }
10 |
11 | async function hey() {
12 |   await 42;
13 |
14 |   readFile("fd-3.mjs").catch((e) => {
       ^
ENOENT: No such file or directory
   errno: -2
 syscall: "open"
   path: "fd-3.mjs"

      at fd-2.mjs:14:3

Before:

ENOENT: No such file or directory
   errno: -2
 syscall: "open"
   path: "fd-3.mjs"

Worth reading what v8 does

I don't think this PR's approach is quite right. This is only 1 stack frame, and only when using this special AsyncPromise in Zig/C++. It doesn't chain.

I think it'd be better to reuse the extra context argument in the await-specific code to have a reference to the StackFrame (though ideally without creating an additional JSCell)

cc @dcrousso incase you find this interesting

I did a little benchmarking and couldn't find a measurable performance impact to this

How did you verify your code works?

Copy link
Contributor

github-actions bot commented Jun 18, 2024

@Jarred-Sumner, your commit has failing tests :(

💪 1 failing tests Darwin AARCH64

  • test/js/bun/test/stack.test.ts 1 failing

💻 2 failing tests Darwin x64 baseline

  • test/js/bun/test/stack.test.ts 1 failing
  • test/js/web/workers/worker.test.ts 1 failing

💻 1 failing tests Darwin x64

  • test/js/bun/test/stack.test.ts 1 failing

🐧💪 1 failing tests Linux AARCH64

  • test/js/bun/test/stack.test.ts 1 failing

🐧🖥 2 failing tests Linux x64 baseline

  • test/js/bun/test/stack.test.ts 1 failing
  • test/regression/issue/09041.test.ts 1 failing

🐧🖥 1 failing tests Linux x64

  • test/js/bun/test/stack.test.ts 1 failing

🪟💻 2 failing tests Windows x64 baseline

  • test/integration/next-pages/test/dev-server.test.ts 1 failing
  • test/js/bun/test/stack.test.ts 1 failing

View logs

@dcrousso
Copy link

support for capturing and linking stack traces across async boundaries was added to Web Inspector in 252543@main by instrumenting queueMicrotask (and JSMicrotask::run). perhaps yall could use/duplicate that logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants