Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

【震惊】Node爆惊天大bug,影响数千万Node.js进程!他竟然一行代码就修复了!他到底做了啥?

$
0
0

很多天前old big让我测试在async中throw和return的效率,偶然踩中了坑

async function foo() {
    throw new Error();
}
(async function test() {
    for (let i = 0; i < 100000; i++) {
        try {
            await foo();
        } catch (e) {
        }
    }
})();
console.log('done');

是什么原因呢?

下面仅仅四行代码也硬了

for (let i = 0; i < 100000; i++) {
    Promise.reject().catch(e => { });
}
console.log('done');
// 只需一行代码。node就冷静下来了
global.Promise = require('bluebird');
for (let i = 0; i < 100000; i++) {
    Promise.reject().catch(e => { });
}
console.log('done');

Viewing all articles
Browse latest Browse all 14821

Trending Articles