Status: Untriaged
Owner: ----
Type: Bug
New issue 14364 by ilya....@
gmail.com: StackTrace::CurrentStackTrace doesn't do async stack traces
https://bugs.chromium.org/p/v8/issues/detail?id=14364Stack traces captured with `StackTrace::CurrentStackTrace` don't cross the event loop "boundary" unlike stacks captured when constructing an `Error`.
This relates to using v8 with node, which does async stack traces, and was opened as
https://github.com/nodejs/node/issues/50056 initially. (I'm not sure whether "async stack traces" are more of a v8 concern or a node concern.)
**Use case**
I'm using fast-blocked-at, a library which starts a watchdog thread and whenever it appears that the event loop is blocked, it interrupts the isolate[^1] to run `StackTrace::CurrentStackTrace` on it[^2].
Example use:
```js
import blockedAt from "fast-blocked-at";
const yield = () => new Promise((r) => setTimeout(r, 0));
blockedAt((durationMs, stack) => {
console.log(`detected block for ${durationMs}ms`)
console.log(stack)
console.log('---')
}, {
threshold: 100,
interval: 50,
});
async function busySleep(blockMs) {
const start = Date.now();
while (Date.now() - start < blockMs); // blocking loop!
}
async function test() {
await busySleep(1000); // stack trace will be full
await yield();
await busySleep(1000); // stack trace will the chopped at 'test'
}
(async () => {
await test();
await yield(); // allow the heartbeat invoke the callback.
})();
```
This results in:
```
detected block for 975ms
at busySleep (fast-blocked-at/test/await_stack.js:6:5)
at test (fast-blocked-at/test/await_stack.js:10:11)
at main (fast-blocked-at/test/await_stack.js:25:11)
at (unknown) (fast-blocked-at/test/await_stack.js:27:3)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at executeUserEntryPoint (node:internal/modules/run_main:86:12)
at (unknown) (node:internal/main/run_main_module:23:47)
---
detected block for 979ms
at busySleep (fast-blocked-at/test/await_stack.js:6:5)
at test (fast-blocked-at/test/await_stack.js:12:11)
---
```
[^1]:
https://git.sr.ht/~kvakil/fast-blocked-at/tree/master/item/native.cc#L124[^2]:
https://git.sr.ht/~kvakil/fast-blocked-at/tree/master/item/native.cc#L246--
You received this message because:
1. The project was configured to send all issue notifications to this address
You may adjust your notification preferences at:
https://bugs.chromium.org/hosting/settings