(Warning) Turning a Promise Sync, async hoot stack has become corrupted
See original GitHub issueWhen turning a Promise into a synchronous Promise
Facing the following error: async hook stack has become corrupted
Error: async hook stack has become corrupted (actual: 6, expected: 7)
1: v8::SnapshotCreator::`default constructor closure'
2: node::CallbackScope::~CallbackScope
3: node::CallbackScope::~CallbackScope
4: RAND_query_egd_bytes
5: RAND_query_egd_bytes
6: uv_timer_get_repeat
7: uv_run
8: 00007FFB97441281
9: 00007FFB974410B6
10: v8::internal::wasm::SignatureMap::Find
11: v8::internal::Builtins::CallableFor
12: v8::internal::Builtins::CallableFor
13: v8::internal::Builtins::CallableFor
14: 000001B9D57043C1
It occures when an error occured during the execution of the Promise. I can reproduce the error:
function waitPromise(val, time) {
let result = undefined;
new Promise(res => {
setTimeout(() => {
throw new Error('whatever');
res(val);
}, time);
}).then(r => {
result = r;
});
while(!result) {
require('deasync').runLoopOnce();
}
return result;
}
console.log(waitPromise('my name is Bond, JAMES BOND!', 2000));
Make sure that in your Promise you do not have any error at all or the error will occur. Solve it by catching all error in the promise and returning the error as the result.
function waitPromise(val, time) {
let result = undefined;
new Promise((res, rej) => {
setTimeout(() => {
try {
throw new Error('whatever');
res(val);
} catch (error) {
rej(error);
}
}, time);
}).then(r => {
result = r;
}).catch(e => {
result = e;
});
while(!result) {
require('deasync').runLoopOnce();
}
return result;
}
console.log(waitPromise('my name is Bond, JAMES BOND!', 2000));
The same error occurs when using deasync-promise
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
(Warning) Turning a Promise Sync, async hoot stack has become ...
When turning a Promise into a synchronous Promise Facing the following error: async hook stack has become corrupted. Error: async hook stack has...
Read more >async hook stack has become corrupted - node.js
Your code is taking too long to elaborate, which means that multiple requests are filling the async queue until it can't handle it....
Read more >Async Await in Node.js - How to Master it? - Blog - RisingStack
Learn how to use async await in Node.js (async functions) to simplify your callback or Promise based application.
Read more >Features - Bluebird JS
then to get at the promise's value as the callback is always called asynchronously. See the API on synchronous inspection for more information....
Read more >In JavaScript, how is awaiting the result of an async different ...
I'm having a hard time wrapping my head around the use of async/await and regular sync function calls ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As I said:
Instead of rejecting, resolve the error with the object. And process the error outside of the deasync code.
@NotWearingPants Neat. I didn’t know about
callbackify
. Then my example would become: