mjackson / citrus

Parsing Expressions for Ruby
http://mjackson.github.io/citrus
405 stars 28 forks source link

Segfault in Citrus during toml-rb initialization with Ruby 3.0 #60

Open csabahenk opened 3 years ago

csabahenk commented 3 years ago

I get a segfault sporadically when I'm requiring toml-rb. I figured out that this happens when the toml-rb code is loading some Citrus grammars. I report this issue to Citrus as this seems to be incorrect behavior regardless the content of those grammars.

This is what toml-rb is doing:

require 'citrus'
...
ROOT = File.dirname(File.expand_path(__FILE__))
Citrus.load "#{ROOT}/toml-rb/grammars/helper.citrus"
Citrus.load "#{ROOT}/toml-rb/grammars/primitive.citrus"
Citrus.load "#{ROOT}/toml-rb/grammars/array.citrus"
Citrus.load "#{ROOT}/toml-rb/grammars/document.citrus"

In those cases when I bothered to check the crash data, the crash occurred when loading of array.citrus was attempted; I'll post an update if I will find it occuring in another Citrus.load call.

I'm aware of this behavior with Ruby 3.0.x; I'm not sure if it has ever occurred with Ruby 2.x, but I think it hasn't. As this happens during an invocation of a script in an interactive shell, a plausible workaround is to re-run the command, which usually succeeds.

I'm on Arch Linux x86_64, package versions:

> ~/python/scratch/pacmandump.py | ruby -rjson -ryaml -ne 'JSON.load($_).then { |r| r["name"] =~ /\Aruby(-(citrus|toml-rb))?\Z/ and YAML.dump %w[name version packager].map { |k| [k, r[k]] }.to_h, $>}' 
---
name: ruby
version: 3.0.1-1
packager: Anatol Pomozov <anatol.pomozov@gmail.com>
---
name: ruby-citrus
version: 3.0.2-1
packager: Unknown Packager
---
name: ruby-toml-rb
version: 2.0.1-1
packager: Unknown Packager

(Unknown Packager in Arch parlance means "unofficial package").

Crash data:

/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1286: [BUG] Segmentation fault at 0x000055e82611d000
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0055 p:---- s:0291 e:000290 CFUNC  :slice!
c:0054 p:0063 s:0285 e:000284 METHOD /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1286 [FINISH]
c:0053 p:---- s:0276 e:000275 CFUNC  :new
c:0052 p:0139 s:0269 e:000268 METHOD /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1470
c:0051 p:0011 s:0254 e:000253 METHOD /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1330
c:0050 p:0003 s:0249 e:000248 METHOD /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1336
c:0049 p:0006 s:0244 e:000243 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:130 [FINISH]
c:0048 p:0015 s:0239 e:000238 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:122 [FINISH]
c:0047 p:0015 s:0234 e:000233 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:113 [FINISH]
c:0046 p:0015 s:0229 e:000228 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:104 [FINISH]
c:0045 p:0005 s:0224 e:000223 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96 [FINISH]
c:0044 p:---- s:0220 e:000219 CFUNC  :map
c:0043 p:0011 s:0216 e:000215 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96 [FINISH]
c:0042 p:0005 s:0212 e:000211 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89 [FINISH]
c:0041 p:---- s:0208 e:000207 CFUNC  :map
c:0040 p:0011 s:0204 e:000203 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89 [FINISH]
c:0039 p:0008 s:0200 e:000199 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:143 [FINISH]
c:0038 p:0015 s:0197 e:000196 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:131 [FINISH]
c:0037 p:0015 s:0192 e:000191 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:122 [FINISH]
c:0036 p:0015 s:0187 e:000186 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:113 [FINISH]
c:0035 p:0015 s:0182 e:000181 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:104 [FINISH]
c:0034 p:0005 s:0177 e:000176 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96 [FINISH]
c:0033 p:---- s:0173 e:000172 CFUNC  :map
c:0032 p:0011 s:0169 e:000168 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96 [FINISH]
c:0031 p:0005 s:0165 e:000164 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89 [FINISH]
c:0030 p:---- s:0161 e:000160 CFUNC  :map
c:0029 p:0011 s:0157 e:000156 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89 [FINISH]
c:0028 p:0008 s:0153 e:000152 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:143 [FINISH]
c:0027 p:0015 s:0150 e:000149 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:131 [FINISH]
c:0026 p:0015 s:0145 e:000144 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:122 [FINISH]
c:0025 p:0015 s:0140 e:000139 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:113 [FINISH]
c:0024 p:0015 s:0135 e:000134 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:104 [FINISH]
c:0023 p:0005 s:0130 e:000129 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96 [FINISH]
c:0022 p:---- s:0126 e:000125 CFUNC  :map
c:0021 p:0011 s:0122 e:000121 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96 [FINISH]
c:0020 p:0005 s:0118 e:000117 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89 [FINISH]
c:0019 p:---- s:0114 e:000113 CFUNC  :map
c:0018 p:0011 s:0110 e:000109 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89 [FINISH]
c:0017 p:0015 s:0106 e:000105 METHOD /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:82
c:0016 p:0013 s:0101 e:000098 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:63 [FINISH]
c:0015 p:---- s:0095 e:000094 CFUNC  :each
c:0014 p:0043 s:0091 e:000090 METHOD /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:63
c:0013 p:0005 s:0085 e:000084 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:51 [FINISH]
c:0012 p:---- s:0081 e:000080 CFUNC  :map
c:0011 p:0023 s:0077 e:000076 BLOCK  /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:51 [FINISH]
c:0010 p:0021 s:0074 e:000073 METHOD /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:47
c:0009 p:0070 s:0068 e:000064 METHOD /usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:77
c:0008 p:0195 s:0057 e:000056 TOP    /usr/lib/ruby/gems/3.0.0/gems/toml-rb-2.0.1/lib/toml-rb.rb:17 [FINISH]
c:0007 p:---- s:0054 e:000053 CFUNC  :require
c:0006 p:0081 s:0049 e:000048 RESCUE <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160
c:0005 p:0677 s:0045 e:000044 METHOD <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149
c:0004 p:0029 s:0028 e:000027 TOP    /home/csaba/ruby/bzhttp.rb:7 [FINISH]
c:0003 p:---- s:0025 e:000024 CFUNC  :require
c:0002 p:0195 s:0020 e:000019 METHOD <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85 [FINISH]
c:0001 p:0000 s:0003 E:001fa0 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
<internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
<internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
/home/csaba/ruby/bzhttp.rb:7:in `<top (required)>'
<internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
<internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
<internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
/usr/lib/ruby/gems/3.0.0/gems/toml-rb-2.0.1/lib/toml-rb.rb:17:in `<top (required)>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:77:in `load'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:47:in `eval'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:51:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:51:in `map'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:51:in `block (4 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:63:in `value'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:63:in `each'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:63:in `block in value'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:82:in `value'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89:in `map'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89:in `block (4 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96:in `map'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96:in `block (4 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:104:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:113:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:122:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:131:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:143:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89:in `map'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89:in `block (4 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96:in `map'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96:in `block (4 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:104:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:113:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:122:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:131:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:143:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89:in `map'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:89:in `block (4 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96:in `map'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:96:in `block (4 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:104:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:113:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:122:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus/file.rb:130:in `block (3 levels) in <module:Citrus>'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1336:in `capture'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1330:in `captures'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1470:in `process_events!'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1470:in `new'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1286:in `initialize'
/usr/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1286:in `slice!'

-- Machine register context ------------------------------------------------
 RIP: 0x00007fdad6fa85f5 RBP: 0x000055e825fca090 RSP: 0x00007ffdaa481128
 RAX: 0x00007fdad64afb90 RBX: 0x0000000000000011 RCX: 0x0000000000000000
 RDX: 0x0000000000000088 RDI: 0x00007fdad64afb90 RSI: 0x000055e82611cfc0
  R8: 0x000055e825fca090  R9: 0x0000000000000480 R10: 0x000055e825fca090
 R11: 0x0000000000000005 R12: 0x0000000000000011 R13: 0x0000000000000000
 R14: 0x000055e82611cfc0 R15: 0x000055e8258023b0 EFL: 0x0000000000010202

-- C level backtrace information -------------------------------------------
/usr/lib/libruby.so.3.0(0x7fdad7262f24) [0x7fdad7262f24]
/usr/lib/libruby.so.3.0(0x7fdad70b6892) [0x7fdad70b6892]
/usr/lib/libruby.so.3.0(0x7fdad71d7daa) [0x7fdad71d7daa]
/usr/lib/libc.so.6(__restore_rt+0x0) [0x7fdad6e80f80]
/usr/lib/libc.so.6(0x1645f5) [0x7fdad6fa85f5]
/usr/lib/libruby.so.3.0(0x7fdad704814d) [0x7fdad704814d]
/usr/lib/libruby.so.3.0(rb_ary_tmp_new_from_values+0x43) [0x7fdad7049453]
/usr/lib/libruby.so.3.0(0x7fdad704c7bb) [0x7fdad704c7bb]
/usr/lib/libruby.so.3.0(0x7fdad705289c) [0x7fdad705289c]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(0x7fdad725910b) [0x7fdad725910b]
/usr/lib/libruby.so.3.0(rb_funcallv_kw+0x52) [0x7fdad7259c42]
/usr/lib/libruby.so.3.0(rb_class_new_instance_pass_kw+0x52) [0x7fdad7156862]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_yield+0x78) [0x7fdad7256b48]
/usr/lib/libruby.so.3.0(0x7fdad704b77d) [0x7fdad704b77d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d43b) [0x7fdad724d43b]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_yield+0x78) [0x7fdad7256b48]
/usr/lib/libruby.so.3.0(0x7fdad704b77d) [0x7fdad704b77d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d43b) [0x7fdad724d43b]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_yield+0x78) [0x7fdad7256b48]
/usr/lib/libruby.so.3.0(0x7fdad704b77d) [0x7fdad704b77d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d43b) [0x7fdad724d43b]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_yield+0x78) [0x7fdad7256b48]
/usr/lib/libruby.so.3.0(0x7fdad704b77d) [0x7fdad704b77d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d43b) [0x7fdad724d43b]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_yield+0x78) [0x7fdad7256b48]
/usr/lib/libruby.so.3.0(0x7fdad704b77d) [0x7fdad704b77d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d43b) [0x7fdad724d43b]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_yield+0x78) [0x7fdad7256b48]
/usr/lib/libruby.so.3.0(0x7fdad704b77d) [0x7fdad704b77d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d43b) [0x7fdad724d43b]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_yield+0x78) [0x7fdad7256b48]
/usr/lib/libruby.so.3.0(rb_ary_each+0x3d) [0x7fdad7044d6d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d43b) [0x7fdad724d43b]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_yield+0x78) [0x7fdad7256b48]
/usr/lib/libruby.so.3.0(0x7fdad704b77d) [0x7fdad704b77d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d43b) [0x7fdad724d43b]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_vm_invoke_bmethod+0x249) [0x7fdad7253599]
/usr/lib/libruby.so.3.0(0x7fdad7253bf7) [0x7fdad7253bf7]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(0x7fdad710a0d8) [0x7fdad710a0d8]
/usr/lib/libruby.so.3.0(rb_require_string+0x2d) [0x7fdad710b16d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad7255049) [0x7fdad7255049]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(0x7fdad710a0d8) [0x7fdad710a0d8]
/usr/lib/libruby.so.3.0(rb_require_string+0x2d) [0x7fdad710b16d]
/usr/lib/libruby.so.3.0(0x7fdad72418af) [0x7fdad72418af]
/usr/lib/libruby.so.3.0(0x7fdad7255049) [0x7fdad7255049]
/usr/lib/libruby.so.3.0(0x7fdad724a7ce) [0x7fdad724a7ce]
/usr/lib/libruby.so.3.0(0x7fdad724d3de) [0x7fdad724d3de]
/usr/lib/libruby.so.3.0(rb_vm_exec+0x1e2) [0x7fdad72523c2]
/usr/lib/libruby.so.3.0(rb_funcallv+0x19c) [0x7fdad725a74c]
/usr/lib/libruby.so.3.0(0x7fdad71d5424) [0x7fdad71d5424]
/usr/lib/libruby.so.3.0(0x7fdad71d640c) [0x7fdad71d640c]
/usr/lib/libruby.so.3.0(ruby_process_options+0x10e) [0x7fdad71d716e]
/usr/lib/libruby.so.3.0(ruby_options+0x103) [0x7fdad70bf563]
ruby(0x55e824037078) [0x55e824037078]
/usr/lib/libc.so.6(__libc_start_main+0xd5) [0x7fdad6e6bb25]
ruby(_start+0x2e) [0x55e8240370ce]
vhiairrassary commented 3 years ago

Same issue on our side. Everything work perfectly until we migrate to Ruby 3.0.2. Here is the top of our trace

/opt/hostedtoolcache/Ruby/3.0.2/x64/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1286: [BUG] Segmentation fault at 0x000055892ffad208
ruby 3.0.2p***7 (2021-07-07 revision 0db68f0233) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0172 p:---- s:***35 e:00***34 CFUNC  :slice!
c:0171 p:0063 s:***29 e:00***28 METHOD /opt/hostedtoolcache/Ruby/3.0.2/x64/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1286 [FINISH]
c:0170 p:---- s:***20 e:00***19 CFUNC  :new
c:0169 p:0139 s:***13 e:00***12 METHOD /opt/hostedtoolcache/Ruby/3.0.2/x64/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1470
c:0168 p:0011 s:0998 e:000997 METHOD /opt/hostedtoolcache/Ruby/3.0.2/x64/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1330
c:0167 p:0003 s:0993 e:000992 METHOD /opt/hostedtoolcache/Ruby/3.0.2/x64/lib/ruby/gems/3.0.0/gems/citrus-3.0.2/lib/citrus.rb:1336
c:0166 p:0062 s:0988 e:000983 BLOCK  (eval):4 [FINISH]

As said above, it does not seem to happen on every run. Issue happens on macOS & Ubuntu.

vhiairrassary commented 3 years ago

Minimal reproduction is available at https://github.com/vhiairrassary/citrus-issue-60. To reproduce the issue, I just use the calc grammar from citrus and run it indefinitely until it crashes. Full stack trace is available in the repository README.md file.

require 'citrus'
Citrus.load 'calc'

loop do
  puts Calc.parse('1 + 2 + 3').value
end
flavorjones commented 3 years ago

Please note that this is a bug in Ruby 3.0.0-3.0.2. I've reported it upstream at https://bugs.ruby-lang.org/issues/18138 and submitted a PR to fix it at https://github.com/ruby/ruby/pull/4787

In the meantime, I'll submit a PR to citrus that will work around the bug conditions.

flavorjones commented 3 years ago

See PR at #61

flavorjones commented 3 years ago

Note that the underlying issue is fixed in Ruby 3.0.3.