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
[ Bug ] parseFiles callback is called after the returning promise is resolved #206
Comments
Thanks for the reporting and the detailed reproduction! It is very helpful! I have found the root cause of the problem. Sorry to introduce this bug due to my limited understanding of Napi and NodeJS. Here is the detailed walk through of this bug. I hope it can help you. BackgroundThe The crux of the problem is that calling thread safe function in napi from Rust will not actually call the JavaScript function. Instead, the callback task is pushed to a queue as a record. IssueI expect the So when will the queue execution be yielded? InvestigationI investigated the Further ReproI tried another way to reproduce the issue by reducing the file items. Curiously, the returning promise almost always stop when file count is 999. It probably means that NodeJS will suspend the callback execution when item count reaches 1000. So I "GitHub Search"ed the NodeJS core. Fortunately the Indeed! NodeJS' event loop will not drain the sync task queue! After 1000 files are processed by JavaScript, NodeJS will take a break to make event loop progress. But Rust will ruthlessly push all files to the queue. And the |
Fixed in ac266db |
This is not fixable in JavaScript world. Nothing to do from our side so the issue is closed. |
Summary
callback of
parseFiles
is called even afterparseFiles
promise is resolved.Reproduction repo
https://github.com/ShenQingchuan/repro-sg-parse-files-0.2.2
Reproduction
You could see this kind of output in reproduction:
the async function
runAstGrepParse
is not worked as expected, it should end after every callback function synchronously executed.Issue cause
https://github.com/nodejs/node/blob/8ba54e50496a6a5c21d93133df60a9f7cb6c46ce/src/node_api.cc#L336
The text was updated successfully, but these errors were encountered: