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

Unhandled promise rejection aborts the process #571

Closed
Veetaha opened this issue Mar 8, 2020 · 2 comments · Fixed by #822
Closed

Unhandled promise rejection aborts the process #571

Veetaha opened this issue Mar 8, 2020 · 2 comments · Fixed by #822

Comments

@Veetaha
Copy link

Veetaha commented Mar 8, 2020

Tree sitter compiled with emscripten (which I guess is currently distributed via npm) aborts the process in case of any unhandled promise rejections.
This is very weird and not acceptable.
The investigation on this issue was initiated at totally unrealted rust-analyzer repo. It was quite hard-to-debug since it involved quite a lot of parties and stars to match in order to reproduce.

Steps to reproduce:

require("web-tree-sitter");

Promise.reject(new Error("My error"));

setTimeout(() => {
    console.log("Hello world! 10 seconds after");
}, 10000)

See the following logs (the process is terminated without consulting the user)

Error: My error
Error: My error
/home/veetaha/my/junk/rollup/node_modules/web-tree-sitter/tree-sitter.js:1
var Module=void 0!==Module?Module:{};!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():window.TreeSitter=t()}(0,function(){var e,t={};for(e in Module)Module.hasOwnProperty(e)&&(t[e]=Module[e]);var r,n,o=[],s=function(e,t){throw t},_=!1,a=!1;_="object"==typeof window,a="function"==typeof importScripts,r="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,n=!_&&!r&&!a;var u,i,l,d,c="";r?(c=a?require("path").dirname(c)+"/":__dirname+"/",u=function(e,t){return l||(l=require("fs")),d||(d=require("path")),e=d.normalize(e),l.readFileSync(e,t?null:"utf8")},i=function(e){var t=u(e,!0);return t.buffer||(t=new Uint8Array(t)),q(t.buffer),t},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),o=process.argv.slice(2),"undefined"!=typeof module&&(module.exports=Module),process.on("uncaughtException",function(e){if(!(e instanceof Ze))thr

RuntimeError: abort(Error: My error). Build with -s ASSERTIONS=1 for more info.
    at process.de (/home/veetaha/my/junk/rollup/node_modules/web-tree-sitter/tree-sitter.js:1:10108)
    at process.emit (events.js:321:20)
    at processPromiseRejections (internal/process/promises.js:209:33)
    at processTicksAndRejections (internal/process/task_queues.js:98:32)

My wild guess is that you should enable NODEJS_CATCH_REJECTION flag somewhere here:

$emcc \
-s WASM=1 \
-s TOTAL_MEMORY=33554432 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MAIN_MODULE=2 \
-s NO_FILESYSTEM=1 \
-s "EXPORTED_FUNCTIONS=${exports}" \
$emscripten_flags \
-std=c99 \
-D 'fprintf(...)=' \
-D NDEBUG= \
-I lib/src \
-I lib/include \
--js-library ${web_dir}/imports.js \
--pre-js ${web_dir}/prefix.js \
--post-js ${web_dir}/binding.js \
lib/src/lib.c \
${web_dir}/binding.c \
-o target/scratch/tree-sitter.js

@maxbrunsfeld
Copy link
Contributor

It seems like this will be the default behavior for Node.js in the future, but I agree that there's no reason for the Tree-sitter module to add a global unhandled rejection listener.

@Veetaha
Copy link
Author

Veetaha commented Mar 9, 2020

Yeah, if node switches to this behavior in the future, then I guess the whole world will fall in an apocalypse... Anyway, we are not there yet...

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 a pull request may close this issue.

2 participants