You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
terminated by signal SIGSEGV (Address boundary error) #72
I am no expert in nodejs - this happens to me when running larger queries. Is this a bug or this means I should do some sort special nodejs configuration?
Thanks for the report. I think it’s a bug. What language are you parsing? Is the grammar open source? It’d be great to get a reproducible script that causes this.
tree-sitter-php@^0.16.2:
version "0.16.2"
resolved "https://registry.yarnpkg.com/tree-sitter-php/-/tree-sitter-php-0.16.2.tgz#15c48dbd44cc56c4660d48ef883c9fc0f3e0d35b"
integrity sha512-BkewhybED1xRQkDpmXkjpBZ1OdnWcmjyu3tGRsoiFqbeNeDtWxac2wzpBdkQr+aSUKlJoCkpBFytM1KcQa5SoA==
dependencies:
nan "^2.14.0"
[EDIT] For the record, tree-sitter-node version in use:
tree-sitter@^0.17.1:
version "0.17.1"
resolved "https://registry.yarnpkg.com/tree-sitter/-/tree-sitter-0.17.1.tgz#821c5a4ac1afdb623d63f5ffc7916663e732a95c"
integrity sha512-obIe804bwfAGFMhTjQz0NXF75GDupCVXo7Sv0NVVdA3s/Q4ZI4mdirIN8cpw6bVhz/K1qgUdEuI3SEoOE/q75A==
dependencies:
nan "^2.14.0"
prebuild-install "^5.0.0"
Hmm, I still can't reproduce it. I also tried repeating the entire keywords list until it was ~500 lines long, and substituting some larger PHP source code for the text. Still runs ok on macOS.
If you get a chance, could you rebuild the tree-sitter module in debug mode, and run this script with a debugger?
To rebuild the module:
npm install -g node-gyp
cd node_modules/tree-sitter
node-gyp rebuild --debug
Then, to run:
lldb node -- test.js
Since the trace ends at Query._init, I would recommend setting a breakpoint in Query::GetPredicates, which is the only native function called by_init:
(lldb) breakpoint set -n Query::GetPredicates
(lldb) run
Thank you for helping me out!
Here is the debugging session for the snippet from above:
05:11:00, /tmp/preview
> lldb node -- index.js
(lldb) target create "node"
Current executable set to 'node' (x86_64).
(lldb) settings set -- target.run-args "index.js"
(lldb) breakpoint set -n Query::GetPredicates
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) run
Process 107097 launched: '/usr/bin/node' (x86_64)
1 location added to breakpoint 1
Process 107097 stopped
* thread #1, name = 'node', stop reason = breakpoint 1.1
frame #0: 0x00007ffff46678a4 tree_sitter_runtime_binding.node`node_tree_sitter::Query::GetPredicates(info=0x00007fffffffc3d0) at query.cc:145:48
142 }
143
144 void Query::GetPredicates(const Nan::FunctionCallbackInfo<Value> &info) {
-> 145 Query *query = Query::UnwrapQuery(info.This());
146 auto ts_query = query->query_;
147
148 auto pattern_len = ts_query_pattern_count(ts_query);
(lldb) n
Process 107097 stopped
* thread #1, name = 'node', stop reason = step over
frame #0: 0x00007ffff46678d5 tree_sitter_runtime_binding.node`node_tree_sitter::Query::GetPredicates(info=0x00007fffffffc3d0) at query.cc:146:8
143
144 void Query::GetPredicates(const Nan::FunctionCallbackInfo<Value> &info) {
145 Query *query = Query::UnwrapQuery(info.This());
-> 146 auto ts_query = query->query_;
147
148 auto pattern_len = ts_query_pattern_count(ts_query);
149
(lldb) n
Process 107097 stopped
* thread #1, name = 'node', stop reason = step over
frame #0: 0x00007ffff46678e1 tree_sitter_runtime_binding.node`node_tree_sitter::Query::GetPredicates(info=0x00007fffffffc3d0) at query.cc:148:44
145 Query *query = Query::UnwrapQuery(info.This());
146 auto ts_query = query->query_;
147
-> 148 auto pattern_len = ts_query_pattern_count(ts_query);
149
150 Local<Array> js_predicates = Nan::New<Array>();
151
(lldb) s
Process 107097 stopped
* thread #1, name = 'node', stop reason = step in
frame #0: 0x00007ffff46830cc tree_sitter_runtime_binding.node`ts_query_pattern_count(self=0x0000000000000000) at query.c:2077:24
2074 }
2075
2076 uint32_t ts_query_pattern_count(const TSQuery *self) {
-> 2077 return self->patterns.size;
2078 }
2079
2080 uint32_t ts_query_capture_count(const TSQuery *self) {
(lldb) s
Process 107097 stopped
* thread #1, name = 'node', stop reason = signal SIGSEGV: invalid address (fault address: 0x78)
frame #0: 0x00007ffff46830d0 tree_sitter_runtime_binding.node`ts_query_pattern_count(self=0x0000000000000000) at query.c:2077:24
2074 }
2075
2076 uint32_t ts_query_pattern_count(const TSQuery *self) {
-> 2077 return self->patterns.size;
2078 }
2079
2080 uint32_t ts_query_capture_count(const TSQuery *self) {
(lldb) s
Process 107097 stopped
* thread #1, name = 'node', stop reason = unknown crash reason
frame #0: 0x00007ffff46830d0 tree_sitter_runtime_binding.node`ts_query_pattern_count(self=0x0000000000000000) at query.c:2077:24
2074 }
2075
2076 uint32_t ts_query_pattern_count(const TSQuery *self) {
-> 2077 return self->patterns.size;
2078 }
2079
2080 uint32_t ts_query_capture_count(const TSQuery *self) {
(lldb) s
Process 107097 exited with status = 11 (0x0000000b)
(lldb) s
error: invalid thread
(lldb)
Also, during issue (once you said you cannot reproduce), I updated nodejs 14 -> 15 and clang 10 -> 11
Since then, error now alternates between the SIGSEGV (more often) and Query error (less often):
05:15:57, last:139, /tmp/preview
> node index.js
fish: “node index.js” terminated by signal SIGSEGV (Address boundary error)
05:15:58, last:139, /tmp/preview
> node index.js
/tmp/preview/index.js:28
(new Parser.Query(PHP, query)).matches(tree.rootNode)
^
Error: Query error of type TSQueryErrorNodeType at position 317
at Object.<anonymous> (/tmp/preview/index.js:28:2)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
I have a more pernicious seg fault that is ONLY triggered in a Docker environment, which has more limited memory. It's possible that this bug is separate from the one above, and is triggered by an out-of-memory error in Query.
but ONLY in a Docker context, and only inside a jest test. Note that the seg fault occurs in lib_pthread, so this is a threading issue. I am almost certain the NAPI PR will fix this.
Activity
talbergs commentedon Dec 12, 2020
Few last lines of
node --trace ./app.js runmaxbrunsfeld commentedon Dec 13, 2020
Thanks for the report. I think it’s a bug. What language are you parsing? Is the grammar open source? It’d be great to get a reproducible script that causes this.
talbergs commentedon Dec 16, 2020
I parse php using this grammar
[EDIT] For the record, tree-sitter-node version in use:
talbergs commentedon Dec 16, 2020
This snippet currently reproduces the error. Delete last element from "keywords" array and error goes away.
maxbrunsfeld commentedon Dec 16, 2020
I can't reproduce the problem using this script. What platform are you on?
talbergs commentedon Dec 16, 2020
Maybe try a bit larger query on your machine, like:
maxbrunsfeld commentedon Dec 16, 2020
Hmm, I still can't reproduce it. I also tried repeating the entire
keywordslist until it was ~500 lines long, and substituting some larger PHP source code for the text. Still runs ok on macOS.If you get a chance, could you rebuild the
tree-sittermodule in debug mode, and run this script with a debugger?To rebuild the module:
npm install -g node-gyp cd node_modules/tree-sitter node-gyp rebuild --debugThen, to run:
Since the trace ends at
Query._init, I would recommend setting a breakpoint inQuery::GetPredicates, which is the only native function called by_init:talbergs commentedon Dec 17, 2020
Thank you for helping me out!
Here is the debugging session for the snippet from above:
Also, during issue (once you said you cannot reproduce), I updated
nodejs14 -> 15 andclang10 -> 11Since then, error now alternates between the SIGSEGV (more often) and Query error (less often):
talbergs commentedon Dec 26, 2020
So we mark this as bug ?
cellog commentedon Jan 29, 2021
I have been able to reliably reproduce a seg fault by passing in a single string to a query instead of an S expression, as in
new Query(Ruby, "oops");I added this to the top of my test:
cellog commentedon Jan 29, 2021
Also note that I arrived here because of jestjs/jest#8769 (comment)
I have a more pernicious seg fault that is ONLY triggered in a Docker environment, which has more limited memory. It's possible that this bug is separate from the one above, and is triggered by an out-of-memory error in Query.
cellog commentedon Jan 29, 2021
Reproduce case:
as in
but ONLY in a Docker context, and only inside a jest test. Note that the seg fault occurs in lib_pthread, so this is a threading issue. I am almost certain the NAPI PR will fix this.
cellog commentedon Jan 29, 2021
further context: the lines
are responsible. If I remove either
or
OR remove both predicates (the
(#eq?then the seg fault disappears.
talbergs commentedon Feb 6, 2021
Thank you @cellog!
What is NAPI PR?
cellog commentedon Feb 7, 2021
#52
fix: prevent Nan::Utf8String destructor call due to out of scope, fixes
fix: prevent Nan::Utf8String destructor call due to out of scope, fixes
talbergs commentedon Mar 11, 2021
I wanted to confirm that actually #81 solves this issue for me, and confirm closing this thread, but building the master branch I get this error:
This time again I am not sure if that is my fault or not.
When would the #81 be released?
MichaelBelousov commentedon Mar 9, 2023
@talbergs
FWIW and in case anyone else runs into this, make sure to clone with submodules: