Tech Racho エンジニアの「?」を「!」に。
  • Ruby / Rails関連

Ruby 3.3.0: aarch64-linux環境でFiber.new{ }.resumeを呼ぶと落ちる問題

この記事の内容は現在進行中なので、今後状況が変わる可能性があります。

追記(2024/04/11)

その後Docker Hubのdocker-library/rubyで本記事の問題が修正されました↓。これにより、Docker HubのRuby 3.3.0イメージは正常に動くようになりました。

  • M1 Macbook Pro 2021, Sonoma 14.2.1
  • Ruby: 3.3.0
  • Rails: 7.2.1
  • Docker: 24.0.6, build ed223bc
  • Docker Desktop for Mac: 4.25.2 (129061)
  • Docker Hub: 3.3.0-slim-bookworm

経緯

Ruby 3.3.0リリースの翌日にDocker Hubでも公式のRubyコンテナが公開されました。

ちょうど某所で「M1 MacのDocker環境でRuby 3.3.0ベースのRailsを動かすと落ちる」という書き込みをたまたま見かけました(その後書き込みは削除されていました)。

もしやと思って、自分のRailsアプリの開発用DockerセットアップをDocker Hubの3.3.0-slim-bookwormでRuby 3.3.0にアップグレードすると、Railsが起動した瞬間にsegmentation faultで落ちてしまいました。

なお、Dockerを使わない素のM1 Macbook環境ではRuby 3.3.0で問題なく動作します。

ログには/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:14で落ちたと表示されています。
念のためrdbgで追いかけてみたところ、やはり同じ箇所で落ちていました↓。

# concurrent-ruby/concurrent/atomic/lock_local_var.rb#L14
Fiber.new { mutex.owned? }.resume

Fiber.new { mutex.owned? }.resumeで何かが起きたようです。


切り分けのため、再現用の新規Railsアプリ+Dockerセットアップを作成しました↓。Docker HubのRuby 3.3.0コンテナではrails newすらsegmentation faultで落ちてしまうため、Ruby 3.2.2コンテナでrails newしてからRuby 3.3.0コンテナにアップグレードする形で再現アプリを作成しました。

参考: hachi8833/rails712_ruby33

再現アプリのエラーログ(クリックで展開)
$ dip rails about
[+] Building 0.0s (0/0)                                                                               docker:desktop-linux
[+] Building 0.0s (0/0)                                                                               docker:desktop-linux
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:14: [BUG] Segmentation fault at 0x0057ffff94e306c0
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [aarch64-linux]

-- Control frame information -----------------------------------------------
c:0100 p:---- s:0565 e:000564 CFUNC  :resume
c:0099 p:0007 s:0561 E:001540 BLOCK  /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:14 [FINISH]
c:0098 p:---- s:0558 e:000557 CFUNC  :synchronize
c:0097 p:0026 s:0554 E:000ca8 METHOD /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:12
c:0096 p:0007 s:0549 e:000548 CLASS  /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:18
c:0095 p:0025 s:0546 e:000545 TOP    /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:5 [FINISH]
c:0094 p:---- s:0543 e:000542 CFUNC  :require
c:0093 p:0030 s:0538 e:000537 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0092 p:0158 s:0532 e:000531 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0091 p:0041 s:0522 e:000521 TOP    /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb:7 [FINISH]
c:0090 p:---- s:0519 e:000518 CFUNC  :require
c:0089 p:0030 s:0514 e:000513 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0088 p:0158 s:0508 e:000507 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0087 p:0047 s:0498 e:000497 TOP    /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomics.rb:8 [FINISH]
c:0086 p:---- s:0495 e:000494 CFUNC  :require
c:0085 p:0030 s:0490 e:000489 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0084 p:0158 s:0484 e:000483 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0083 p:0029 s:0474 e:000473 TOP    /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent.rb:6 [FINISH]
c:0082 p:---- s:0471 e:000470 CFUNC  :require
c:0081 p:0030 s:0466 e:000465 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0080 p:0158 s:0460 e:000459 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0079 p:0005 s:0450 e:000449 TOP    /usr/local/bundle/gems/tzinfo-2.0.6/lib/tzinfo/string_deduper.rb:4 [FINISH]
c:0078 p:---- s:0447 e:000446 CFUNC  :require_relative
c:0077 p:0025 s:0442 e:000441 TOP    /usr/local/bundle/gems/tzinfo-2.0.6/lib/tzinfo.rb:25 [FINISH]
c:0076 p:---- s:0439 e:000438 CFUNC  :require
c:0075 p:0030 s:0434 e:000433 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0074 p:0158 s:0428 e:000427 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0073 p:0005 s:0418 e:000417 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/values/time_zone.rb:3 [FINISH]
c:0072 p:---- s:0415 e:000414 CFUNC  :require
c:0071 p:0030 s:0410 e:000409 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0070 p:0158 s:0404 e:000403 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0069 p:0017 s:0394 e:000393 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/core_ext/time/conversions.rb:5 [FINISH]
c:0068 p:---- s:0391 e:000390 CFUNC  :require
c:0067 p:0030 s:0386 e:000385 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0066 p:0158 s:0380 e:000379 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0065 p:0065 s:0370 e:000369 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/core_ext/object/json.rb:14 [FINISH]
c:0064 p:---- s:0367 e:000366 CFUNC  :require
c:0063 p:0030 s:0362 e:000361 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0062 p:0158 s:0356 e:000355 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0061 p:0005 s:0346 e:000345 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/json/encoding.rb:3 [FINISH]
c:0060 p:---- s:0343 e:000342 CFUNC  :require
c:0059 p:0030 s:0338 e:000337 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0058 p:0158 s:0332 e:000331 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0057 p:0011 s:0322 e:000321 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/json.rb:4 [FINISH]
c:0056 p:---- s:0319 e:000318 CFUNC  :require
c:0055 p:0030 s:0314 e:000313 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0054 p:0158 s:0308 e:000307 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0053 p:0011 s:0298 e:000297 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/messages/metadata.rb:4 [FINISH]
c:0052 p:---- s:0295 e:000294 CFUNC  :require_relative
c:0051 p:0011 s:0290 e:000289 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/messages/codec.rb:4 [FINISH]
c:0050 p:---- s:0287 e:000286 CFUNC  :require
c:0049 p:0030 s:0282 e:000281 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0048 p:0158 s:0276 e:000275 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0047 p:0023 s:0266 e:000265 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/message_encryptor.rb:6 [FINISH]
c:0046 p:---- s:0263 e:000262 CFUNC  :require
c:0045 p:0030 s:0258 e:000257 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0044 p:0158 s:0252 e:000251 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0043 p:0017 s:0242 e:000241 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/encrypted_file.rb:5 [FINISH]
c:0042 p:---- s:0239 e:000238 CFUNC  :require
c:0041 p:0030 s:0234 e:000233 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0040 p:0158 s:0228 e:000227 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0039 p:0011 s:0218 e:000217 TOP    /usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/encrypted_configuration.rb:4 [FINISH]
c:0038 p:---- s:0215 e:000214 CFUNC  :require
c:0037 p:0030 s:0210 e:000209 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0036 p:0158 s:0204 e:000203 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0035 p:0041 s:0194 e:000193 TOP    /usr/local/bundle/gems/railties-7.1.2/lib/rails/application.rb:9 [FINISH]
c:0034 p:---- s:0191 e:000190 CFUNC  :require
c:0033 p:0030 s:0186 e:000185 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0032 p:0158 s:0180 e:000179 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0031 p:0059 s:0170 e:000169 TOP    /usr/local/bundle/gems/railties-7.1.2/lib/rails.rb:15 [FINISH]
c:0030 p:---- s:0167 e:000166 CFUNC  :require
c:0029 p:0030 s:0162 e:000161 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0028 p:0158 s:0156 e:000155 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0027 p:0005 s:0146 e:000145 TOP    /usr/local/bundle/gems/railties-7.1.2/lib/rails/all.rb:5 [FINISH]
c:0026 p:---- s:0143 e:000142 CFUNC  :require
c:0025 p:0030 s:0138 e:000137 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0024 p:0158 s:0132 e:000131 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0023 p:0011 s:0122 e:000121 TOP    /app/config/application.rb:3 [FINISH]
c:0022 p:---- s:0119 e:000118 CFUNC  :require_relative
c:0021 p:0005 s:0114 e:000113 TOP    /app/rakefile:4 [FINISH]
c:0020 p:---- s:0111 e:000110 CFUNC  :load
c:0019 p:0005 s:0106 e:000105 METHOD /usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/rake_module.rb:29
c:0018 p:0143 s:0101 e:000100 METHOD /usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:734
c:0017 p:0003 s:0095 e:000094 BLOCK  /usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:126
c:0016 p:0002 s:0092 e:000091 METHOD /usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:208
c:0015 p:0004 s:0087 e:000086 METHOD /usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:125
c:0014 p:0021 s:0083 e:000082 BLOCK  /usr/local/bundle/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:43
c:0013 p:0023 s:0079 e:000078 METHOD /usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/rake_module.rb:59
c:0012 p:0021 s:0073 e:000072 METHOD /usr/local/bundle/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:41
c:0011 p:0010 s:0066 e:000065 METHOD /usr/local/bundle/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:20
c:0010 p:0032 s:0059 e:000058 METHOD /usr/local/bundle/gems/railties-7.1.2/lib/rails/command.rb:156
c:0009 p:0035 s:0052 e:000051 BLOCK  /usr/local/bundle/gems/railties-7.1.2/lib/rails/command.rb:73
c:0008 p:0015 s:0049 e:000048 METHOD /usr/local/bundle/gems/railties-7.1.2/lib/rails/command.rb:149
c:0007 p:0048 s:0043 e:000042 METHOD /usr/local/bundle/gems/railties-7.1.2/lib/rails/command.rb:69
c:0006 p:0038 s:0032 e:000031 TOP    /usr/local/bundle/gems/railties-7.1.2/lib/rails/commands.rb:18 [FINISH]
c:0005 p:---- s:0027 e:000026 CFUNC  :require
c:0004 p:0030 s:0022 e:000021 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74
c:0003 p:0158 s:0016 e:000015 METHOD /usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0002 p:0024 s:0006 e:000005 EVAL   bin/rails:4 [FINISH]
c:0001 p:0000 s:0003 E:0019e0 DUMMY  [FINISH]

-- Ruby level backtrace information ----------------------------------------
bin/rails:4:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/commands.rb:18:in `<main>'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/command.rb:69:in `invoke'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/command.rb:149:in `with_argv'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/command.rb:73:in `block in invoke'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/command.rb:156:in `invoke_rake'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
/usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/rake_module.rb:59:in `with_application'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:43:in `block in with_rake'
/usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:125:in `load_rakefile'
/usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
/usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:126:in `block in load_rakefile'
/usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:734:in `raw_load_rakefile'
/usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/rake_module.rb:29:in `load_rakefile'
/usr/local/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/rake_module.rb:29:in `load'
/app/rakefile:4:in `<main>'
/app/rakefile:4:in `require_relative'
/app/config/application.rb:3:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/all.rb:5:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/railties-7.1.2/lib/rails.rb:15:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/railties-7.1.2/lib/rails/application.rb:9:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/encrypted_configuration.rb:4:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/encrypted_file.rb:5:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/message_encryptor.rb:6:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/messages/codec.rb:4:in `<main>'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/messages/codec.rb:4:in `require_relative'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/messages/metadata.rb:4:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/json.rb:4:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/json/encoding.rb:3:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/core_ext/object/json.rb:14:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/core_ext/time/conversions.rb:5:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/activesupport-7.1.2/lib/active_support/values/time_zone.rb:3:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/tzinfo-2.0.6/lib/tzinfo.rb:25:in `<main>'
/usr/local/bundle/gems/tzinfo-2.0.6/lib/tzinfo.rb:25:in `require_relative'
/usr/local/bundle/gems/tzinfo-2.0.6/lib/tzinfo/string_deduper.rb:4:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent.rb:6:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomics.rb:8:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb:7:in `<main>'
/usr/local/bundle/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:5:in `<main>'
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:18:in `<module:Concurrent>'
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:12:in `mutex_owned_per_thread?'
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:12:in `synchronize'
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:14:in `block in mutex_owned_per_thread?'
/usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb:14:in `resume'

-- Threading information ---------------------------------------------------
Total ractor count: 1
Ruby thread count for this ractor: 1

-- Machine register context ------------------------------------------------
  x0: 0x0000aaab0b56eb50  x1: 0x0000aaab0c897b80  x2: 0x0000ffffc56732b0
  x3: 0x0000ffff7ab2ff60  x4: 0x0000ffff7ab30018  x5: 0x0000ffff7ab50000
  x6: 0x0000ffff9537db88  x7: 0x0000000000000000 x18: 0x000000000000744b
 x19: 0x0000000000000000 x20: 0x0000000000000000 x21: 0x0000000000000000
 x22: 0x0000000000000000 x23: 0x0000000000000000 x24: 0x0000000000000000
 x25: 0x0000000000000000 x26: 0x0000000000000000 x27: 0x0000000000000000
 x28: 0x0000000000000000 x29: 0x0000000000000000  sp: 0x0000ffff7ab30000
 fau: 0x0057ffff94e306c0

-- C level backtrace information -------------------------------------------

その後の進展

上の再現アプリを添えて、concurrent-rubyのリポジトリで以下のissueをオープンしました。

参考: Fiber.new causes SEGV when using Ruby 3.3.0 on Rails 7.1.2 in M1 Mac Docker environment · Issue #1020 · ruby-concurrency/concurrent-ruby -- closed

すると、以下の#20085で既にissueが上がっているとコメントで教わりました。お騒がせしました🙇。

参考: Bug #20085: Fiber.new{ }.resume causes Segmentation fault for Ruby 3.3.0 on aarch64-linux - Ruby master - Ruby Issue Tracking System

自分は当初、Ruby 3.3.0とDockerの組み合わせに問題があるのかと思っていましたが、issueを見てみると、Dockerに限らずaarch64-linux環境で動かした場合に落ちるのだそうです。具体的には、Fiber.new{ }.resumeが呼び出されると落ちます。


そしてkateinoigakukunさんが原因を突き止めてくれました。RubyをビルドするコンフィグでCFLAGSには-mbranch-protection=pac-retが設定されているが、ASFLAGSには設定されていなかったためだそうです。aarch64-linux向けのコンフィグの不整合だったんですね。

Ruby 3.3.0を自分でビルドするのであれば、以下のコンフィグを追加することで回避できるそうです。

./configure ASFLAGS=-mbranch-protection=pac-ret

その後kateinoigakukunさんによって以下の修正プルリクがオープンされました(その後、本記事公開直前にマージされました)。

参考: [Bug #20085] Use consistent default options for -mbranch-protection by kateinoigakukun · Pull Request #9371 · ruby/ruby

Ruby 3.3.0では他にも以下のようなバグ修正↓があがっているので、近いうちにRuby 3.3.1がリリースされるのではないかと予想しています。M1 MacbookでDocker Hubの公式Rubyイメージを使うのであれば、Ruby 3.3.1がリリースされるのを待つ方がよさそうです。

参考: Bug #20083: String#match? behaving inconsistently with Ruby 3.3.0 - Ruby master - Ruby Issue Tracking System
参考: Fix [Bug #20083]: correct a cache point size for atomic groups by makenowjust · Pull Request #9367 · ruby/ruby -- 現在オープン(2024/01/09: その後マージされました)

追記(2024/04/11)

記事冒頭に追記したとおり、Docker Hubの公式Rubyイメージは既に修正されました。現時点ではRuby 3.3.1はまだリリースされていません。

関連記事

Ruby 3.3.0がリリースされました


CONTACT

TechRachoでは、パートナーシップをご検討いただける方からの
ご連絡をお待ちしております。ぜひお気軽にご意見・ご相談ください。