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

Seg Fault when running ruby google-protobuf 3.22.2 and newer #12904

Closed
lamphanqg opened this issue May 25, 2023 · 9 comments
Closed

Seg Fault when running ruby google-protobuf 3.22.2 and newer #12904

lamphanqg opened this issue May 25, 2023 · 9 comments
Assignees
Labels

Comments

@lamphanqg
Copy link

What version of protobuf and what language are you using?
Version: from 3.22.2 to 3.23.1 (no problem in 3.22.1)
Language: ruby

What operating system (Linux, Windows, ...) and version?
alpine3.18 (docker image running in mac m1)

What runtime / compiler are you using (e.g., python version or gcc version)
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [aarch64-linux-musl]

What did you do?

  1. Initialize a basic Rails project
  2. Add gem google-protobuf (any version from 3.22.2 to 3.23.1)
  3. Run bundle install
  4. Run bundle exec rails s

I created a test repo here https://github.com/lamphanqg/test_protobuf
You can clone it, run docker-compose run --rm ruby bash, then bundle install and bundle exec rails s inside the container.

What did you expect to see
Rails server can start like with version 3.22.1

What did you see instead?

ca36f1ce0afa:/test_protobuf# bundle exec rails s
/usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_pb.rb:7: [BUG] Segmentation fault at 0x00000000000035d0
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [aarch64-linux-musl]

-- Control frame information -----------------------------------------------
c:0036 p:---- s:0265 e:000264 CFUNC  :add_serialized_file
c:0035 p:0031 s:0260 e:000259 TOP    /usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_pb.rb:7 [FINISH]
c:0034 p:---- s:0256 e:000255 CFUNC  :require
c:0033 p:0011 s:0251 e:000250 METHOD <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37
c:0032 p:0158 s:0236 e:000235 METHOD /usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0031 p:0013 s:0226 e:000225 TOP    /usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_dsl.rb:9 [FINISH]
c:0030 p:---- s:0222 e:000221 CFUNC  :require
c:0029 p:0011 s:0217 e:000216 METHOD <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37
c:0028 p:0158 s:0202 e:000201 METHOD /usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0027 p:0064 s:0192 e:000191 TOP    /usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf.rb:56 [FINISH]
c:0026 p:---- s:0189 e:000188 CFUNC  :require
c:0025 p:0011 s:0184 e:000183 METHOD <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37
c:0024 p:0158 s:0169 e:000168 METHOD /usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0023 p:0069 s:0159 e:000158 RESCUE /usr/local/bundle/gems/bundler-2.4.13/lib/bundler/runtime.rb:73
c:0022 p:0043 s:0155 e:000154 BLOCK  /usr/local/bundle/gems/bundler-2.4.13/lib/bundler/runtime.rb:51 [FINISH]
c:0021 p:---- s:0148 e:000147 CFUNC  :each
c:0020 p:0026 s:0144 e:000143 METHOD /usr/local/bundle/gems/bundler-2.4.13/lib/bundler/runtime.rb:44
c:0019 p:0013 s:0139 e:000138 METHOD /usr/local/bundle/gems/bundler-2.4.13/lib/bundler.rb:187
c:0018 p:0052 s:0134 e:000133 TOP    /test_protobuf/config/application.rb:19 [FINISH]
c:0017 p:---- s:0131 e:000130 CFUNC  :require
c:0016 p:0011 s:0126 e:000125 METHOD <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37
c:0015 p:0158 s:0111 e:000110 METHOD /usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32
c:0014 p:0006 s:0101 e:000100 BLOCK  /usr/local/bundle/gems/railties-7.0.5/lib/rails/commands/server/server_command.rb:137
c:0013 p:0003 s:0096 e:000095 METHOD <internal:kernel>:90
c:0012 p:0022 s:0092 e:000091 METHOD /usr/local/bundle/gems/railties-7.0.5/lib/rails/commands/server/server_command.rb:134
c:0011 p:0054 s:0088 e:000087 METHOD /usr/local/bundle/gems/thor-1.2.2/lib/thor/command.rb:27
c:0010 p:0040 s:0080 e:000079 METHOD /usr/local/bundle/gems/thor-1.2.2/lib/thor/invocation.rb:127
c:0009 p:0213 s:0073 e:000072 METHOD /usr/local/bundle/gems/thor-1.2.2/lib/thor.rb:392
c:0008 p:0030 s:0060 e:000059 METHOD /usr/local/bundle/gems/railties-7.0.5/lib/rails/command/base.rb:87
c:0007 p:0147 s:0053 e:000052 METHOD /usr/local/bundle/gems/railties-7.0.5/lib/rails/command.rb:48
c:0006 p:0038 s:0041 e:000040 TOP    /usr/local/bundle/gems/railties-7.0.5/lib/rails/commands.rb:18 [FINISH]
c:0005 p:---- s:0036 e:000035 CFUNC  :require
c:0004 p:0011 s:0031 e:000030 METHOD <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37
c:0003 p:0158 s:0016 e:000015 METHOD /usr/local/bundle/gems/bootsnap-1.16.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:000c40 DUMMY  [FINISH]

-- Ruby level backtrace information ----------------------------------------
bin/rails:4:in `<main>'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/usr/local/bundle/gems/railties-7.0.5/lib/rails/commands.rb:18:in `<main>'
/usr/local/bundle/gems/railties-7.0.5/lib/rails/command.rb:48:in `invoke'
/usr/local/bundle/gems/railties-7.0.5/lib/rails/command/base.rb:87:in `perform'
/usr/local/bundle/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
/usr/local/bundle/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/bundle/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
/usr/local/bundle/gems/railties-7.0.5/lib/rails/commands/server/server_command.rb:134:in `perform'
<internal:kernel>:90:in `tap'
/usr/local/bundle/gems/railties-7.0.5/lib/rails/commands/server/server_command.rb:137:in `block in perform'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/test_protobuf/config/application.rb:19:in `<main>'
/usr/local/bundle/gems/bundler-2.4.13/lib/bundler.rb:187:in `require'
/usr/local/bundle/gems/bundler-2.4.13/lib/bundler/runtime.rb:44:in `require'
/usr/local/bundle/gems/bundler-2.4.13/lib/bundler/runtime.rb:44:in `each'
/usr/local/bundle/gems/bundler-2.4.13/lib/bundler/runtime.rb:51:in `block in require'
/usr/local/bundle/gems/bundler-2.4.13/lib/bundler/runtime.rb:73:in `rescue in block in require'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf.rb:56:in `<main>'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_dsl.rb:9:in `<main>'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_pb.rb:7:in `<main>'
/usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_pb.rb:7:in `add_serialized_file'

-- Machine register context ------------------------------------------------
  x0: 0x0000ffffce6327fd  x1: 0x0000ffffb28d12be  x2: 0x0000000000000002
  x3: 0x00000000000001cb  x4: 0x0000ffffb28d1130  x5: 0x0000000000000000
  x6: 0x0000000000000001  x7: 0xfffffffffffffff6 x18: 0x0000ffffb27fc1a0
 x19: 0x0000000000000002 x20: 0x0000ffffb28be000 x21: 0x0000ffffb27fcc88
 x22: 0x0000ffffb28be8e0 x23: 0x0000ffffce6327e0 x24: 0x0000ffffce632da0
 x25: 0x0000ffffb28be000 x26: 0x0000ffffb28be8e0 x27: 0x0000ffffb28d12be
 x28: 0x0000ffffb28d1130 x29: 0x0000ffffce632790  sp: 0x0000ffffce632790
 fau: 0x00000000000035d0
...

Please check full log in attached file. It's too long to paste here.
log.txt

Anything else we should know about your project / environment
Actually we don't use protobuf directly. It's just a dependency of the pg_query gem that we use.

@lamphanqg lamphanqg added the untriaged auto added to all issues by default when created. label May 25, 2023
@hlopko hlopko added bug and removed untriaged auto added to all issues by default when created. labels May 26, 2023
@tk3fftk
Copy link

tk3fftk commented Jun 13, 2023

Similar issue has been happened and pinning google-protobuf to 3.22.1 is working.
Our issue was not always happend so restarting the process was a workaround in our environment.

What version of protobuf and what language are you using?
Version: 3.23.2
Language: ruby

What operating system (Linux, Windows, ...) and version?

Linux (debian 10.13 docker image, running on Amazon Linux 2)

What runtime / compiler are you using (e.g., python version or gcc version)
ruby 3.0.6

What did you see instead?

error logs
            "message": "-- C level backtrace information -------------------------------------------",
            "message": " R11: 0x0000563d94887950 R12: 0xcccccccccccccccd R13: 0x000000000008738e",
            "message": " R14: 0x0000000000005024 R15: 0x0000563d957e8028 EFL: 0x0000000000010202",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:123: [BUG] Segmentation fault at 0x00007fc298af1fe6",
            "message": "ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]",
            "message": "-- Control frame information -----------------------------------------------",
            "message": "c:0047 p:---- s:0225 e:000224 CFUNC  :each",
            "message": "c:0046 p:---- s:0222 e:000221 CFUNC  :map",
            "message": "c:0045 p:0032 s:0218 e:000214 BLOCK  /usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:123 [FINISH]",
            "message": "c:0044 p:---- s:0208 e:000207 IFUNC ",
            "message": "c:0043 p:---- s:0205 e:000204 CFUNC  :each",
            "message": "c:0042 p:---- s:0202 e:000201 CFUNC  :each_with_object",
            "message": "c:0041 p:0094 s:0197 e:000196 CLASS  /usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:122",
            "message": "c:0040 p:0007 s:0194 e:000193 CLASS  /usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:22",
            "message": "c:0039 p:0007 s:0191 e:000190 CLASS  /usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:21",
            "message": "c:0038 p:0007 s:0188 e:000187 CLASS  /usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:20",
            "message": "c:0037 p:0007 s:0185 e:000184 TOP    /usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:19 [FINISH]",
            "message": "c:0036 p:---- s:0182 e:000181 CFUNC  :require",
            "message": "c:0035 p:0258 s:0177 e:000176 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32",
            "message": "c:0034 p:0007 s:0167 e:000166 BLOCK  /usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:324",
            "message": "c:0033 p:0068 s:0164 e:000163 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:291",
            "message": "c:0032 p:0010 s:0157 e:000156 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:324",
            "message": "c:0031 p:0047 s:0151 e:000150 TOP    /usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/google_ads_client.rb:27 [FINISH]",
            "message": "c:0030 p:---- s:0148 e:000147 CFUNC  :require",
            "message": "c:0029 p:0258 s:0143 e:000142 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32",
            "message": "c:0028 p:0007 s:0133 e:000132 BLOCK  /usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:324",
            "message": "c:0027 p:0068 s:0130 e:000129 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:291",
            "message": "c:0026 p:0010 s:0123 e:000122 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:324",
            "message": "c:0025 p:0011 s:0117 e:000116 TOP    /usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads.rb:19 [FINISH]",
            "message": "c:0024 p:---- s:0114 e:000113 CFUNC  :require",
            "message": "c:0023 p:0258 s:0109 e:000108 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32",
            "message": "c:0022 p:0032 s:0099 e:000098 BLOCK  /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:74 [FINISH]",
            "message": "c:0021 p:---- s:0094 e:000093 CFUNC  :each",
            "message": "c:0020 p:0042 s:0090 e:000089 BLOCK  /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:69 [FINISH]",
            "message": "c:0019 p:---- s:0083 e:000082 CFUNC  :each",
            "message": "c:0018 p:0026 s:0079 e:000078 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:58",
            "message": "c:0017 p:0013 s:0074 e:000073 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler.rb:174",
            "message": "c:0016 p:0076 s:0069 e:000068 TOP    /work/config/application.rb:11 [FINISH]",
            "message": "c:0015 p:---- s:0065 e:000064 CFUNC  :require_relative",
            "message": "c:0014 p:0005 s:0060 e:000059 TOP    /work/Rakefile:4 [FINISH]",
            "message": "c:0013 p:---- s:0057 e:000056 CFUNC  :load",
            "message": "c:0012 p:0005 s:0052 e:000051 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:29",
            "message": "c:0011 p:0180 s:0047 e:000046 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:710",
            "message": "c:0010 p:0004 s:0041 e:000040 BLOCK  /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:104",
            "message": "c:0009 p:0002 s:0038 e:000037 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186",
            "message": "c:0008 p:0004 s:0033 e:000032 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:103",
            "message": "c:0007 p:0012 s:0029 e:000028 BLOCK  /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:82",
            "message": "c:0006 p:0002 s:0026 e:000025 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186",
            "message": "c:0005 p:0015 s:0021 e:000020 METHOD /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:80",
            "message": "c:0004 p:0019 s:0016 e:000015 TOP    /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/exe/rake:27 [FINISH]",
            "message": "c:0003 p:---- s:0013 e:000012 CFUNC  :load",
            "message": "c:0002 p:0124 s:0008 E:001480 EVAL   /usr/local/bin/rake:25 [FINISH]",
            "message": "c:0001 p:0000 s:0003 E:000540 (none) [FINISH]",
            "message": "-- Ruby level backtrace information ----------------------------------------",
            "message": "/usr/local/bin/rake:25:in `<main>'",
            "message": "/usr/local/bin/rake:25:in `load'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:80:in `run'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:82:in `block in run'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:103:in `load_rakefile'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:104:in `block in load_rakefile'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:710:in `raw_load_rakefile'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:29:in `load_rakefile'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:29:in `load'",
            "message": "/work/Rakefile:4:in `<top (required)>'",
            "message": "/work/Rakefile:4:in `require_relative'",
            "message": "/work/config/application.rb:11:in `<top (required)>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler.rb:174:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `each'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `block in require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `each'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:74:in `block (2 levels) in require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads.rb:19:in `<main>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:324:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:291:in `load_dependency'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:324:in `block in require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/google_ads_client.rb:27:in `<main>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:324:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:291:in `load_dependency'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/activesupport-6.0.4.8/lib/active_support/dependencies.rb:324:in `block in require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:19:in `<main>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:20:in `<module:Google>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:21:in `<module:Ads>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:22:in `<module:GoogleAds>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:122:in `<module:Errors>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:122:in `each_with_object'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:122:in `each'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:123:in `block in <module:Errors>'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:123:in `map'",
            "message": "/usr/local/lib/ruby/gems/3.0.0/gems/google-ads-googleads-22.1.0/lib/google/ads/google_ads/errors.rb:123:in `each'",
            "message": "-- Machine register context ------------------------------------------------",
            "message": " RIP: 0x00007fc298ead799 RBP: 0x0000563d8cd116a0 RSP: 0x00007ffda6a84900",
            "message": " RAX: 0x61e2005d70255b20 RBX: 0x00007fc298b29ca0 RCX: 0x00007fc298af1fe6",
            "message": " RDX: 0x0000000000000037 RDI: 0x0000563d8cd116a0 RSI: 0xcccccccccccccccd",
            "message": "  R8: 0x000000000000002c  R9: 0x0000563d94884010 R10: 0x00007fc29896e870",
(snip)

@haberman
Copy link
Member

I was able to reproduce this. I reduced it to a one-liner:

$ docker run --rm ruby:3.2.2-alpine3.18 /bin/sh -c "apk add gcompat && gem install google-protobuf -v 3.22.2 && ruby -e 'require \"google/protobuf/descriptor_pb\"'"
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/aarch64/APKINDEX.tar.gz
(1/3) Installing musl-obstack (1.2.3-r2)
(2/3) Installing libucontext (1.2-r2)
(3/3) Installing gcompat (1.1.0-r1)
OK: 25 MiB in 39 packages
Successfully installed google-protobuf-3.22.2-aarch64-linux
1 gem installed
/usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_pb.rb:7: [BUG] Segmentation fault at 0x00000000000035d0
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [aarch64-linux-musl]

-- Control frame information -----------------------------------------------
c:0007 p:---- s:0039 e:000038 CFUNC  :add_serialized_file
c:0006 p:0031 s:0034 e:000033 TOP    /usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_pb.rb:7 [FINISH]
c:0005 p:---- s:0030 e:000029 CFUNC  :require
c:0004 p:0049 s:0025 e:000024 RESCUE <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:159
c:0003 p:0275 s:0021 e:000020 METHOD <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:39
c:0002 p:0005 s:0006 e:000005 EVAL   -e:1 [FINISH]
c:0001 p:0000 s:0003 E:000070 DUMMY  [FINISH]

-- Ruby level backtrace information ----------------------------------------
-e:1:in `<main>'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:39:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:159:in `rescue in require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:159:in `require'
/usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_pb.rb:7:in `<top (required)>'
/usr/local/bundle/gems/google-protobuf-3.22.2-aarch64-linux/lib/google/protobuf/descriptor_pb.rb:7:in `add_serialized_file'

-- Machine register context ------------------------------------------------
  x0: 0x0000ffffe24919bd  x1: 0x0000ffff932ef5de  x2: 0x0000000000000002
  x3: 0x00000000000001cb  x4: 0x0000ffff932ef450  x5: 0x0000000000000000
  x6: 0x0000000000000001  x7: 0xfffffffffffffff6 x18: 0x0000ffff932ca230
 x19: 0x0000000000000002 x20: 0x0000ffff9339e000 x21: 0x0000ffff932cad18
 x22: 0x0000ffff9339e8e0 x23: 0x0000ffffe24919a0 x24: 0x0000ffffe2491f60
 x25: 0x0000ffff9339e000 x26: 0x0000ffff9339e8e0 x27: 0x0000ffff932ef5de
 x28: 0x0000ffff932ef450 x29: 0x0000ffffe2491950  sp: 0x0000ffffe2491950
 fau: 0x00000000000035d0

[snip]

I think this started in 3.22.2 because that was the first version that included a binary gem for aarch64-linux.

This also appears to be specific to Alpine and the gcompat package. For the Debian-based Ruby image, it works fine:

$ docker run --rm ruby:3.2.2 /bin/sh -c "gem install google-protobuf -v 3.22.2 && ruby -e 'require \"google/protobuf/descriptor_pb\"'"
[runs successfully without crashing]

@haberman
Copy link
Member

@dazuma This appears to be an issue with the aarch64-linux binary gem.

It seems like there are two possible resolutions:

  1. Attempt to fix the binary gem somehow so that it works with Alpine Linux and gcompat.
  2. Say that Alpine is not supported for the binary gem.

Ideally there would be a way to teach the gem tool that it should use the source gem instead of the binary gem for Alpine. I think it would work fine if it compiled the source gem instead.

@dazuma
Copy link
Contributor

dazuma commented Jun 13, 2023

The binary gems are not compatible with Alpine. This has been a problem since time immemorial, and we haven't yet found a good solution for it. The workaround is to pass --platform ruby to gem install if you're using rubygems directly (see the reference docs), or set the force_ruby_platform bundler config if you're using bundler (see the man page). This will force installation of the source gem, which will be compiled specifically for Alpine at install time.

@haberman
Copy link
Member

Thanks Daniel. I'm closing this bug per #12904 (comment), which has suggested workarounds.

@segiddins
Copy link

@dazuma is there anything preventing publishing precompiled gems with platform $cpu-linux-musl ?

@cswilliams
Copy link

The binary gems are not compatible with Alpine. This has been a problem since time immemorial, and we haven't yet found a good solution for it. The workaround is to pass --platform ruby to gem install if you're using rubygems directly (see the reference docs), or set the force_ruby_platform bundler config if you're using bundler (see the man page). This will force installation of the source gem, which will be compiled specifically for Alpine at install time.

Are there any other work arounds besides setting force_ruby_platform? We're finding that when we set force_ruby_platform, the seg fault does go away, but then we are unable to compile assets with the tailwindcss-rails gem and get this error:

23:10:51 css.1  | rails aborted!
23:10:51 css.1  | Tailwindcss::Commands::ExecutableNotFoundException: Cannot find the tailwindcss executable for aarch64-linux in /usr/local/bundle/gems/tailwindcss-rails-2.0.30/exe
23:10:51 css.1  |
23:10:51 css.1  | If you're using bundler, please make sure you're on the latest bundler version:
23:10:51 css.1  |
23:10:51 css.1  |     gem install bundler
23:10:51 css.1  |     bundle update --bundler
23:10:51 css.1  |
23:10:51 css.1  | Then make sure your lock file includes this platform by running:
23:10:51 css.1  |
23:10:51 css.1  |     bundle lock --add-platform aarch64-linux
23:10:51 css.1  |     bundle install
23:10:51 css.1  |
23:10:51 css.1  | See `bundle lock --help` output for details.
23:10:51 css.1  |
23:10:51 css.1  | If you're still seeing this message after taking those steps, try running
23:10:51 css.1  | `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
23:10:51 css.1  | https://github.com/rails/tailwindcss-rails#check-bundle_force_ruby_platform
23:10:51 css.1  | for more details.

It seems like tailwindcss-rails is not compatible with the force_ruby_platform setting.

One temporary but not great solution, I find if I edit our Gemfile.lock by hand and change google-protobuf (3.24.1-aarch64-linux) to google-protobuf (3.24.1), then the segfault goes away and we're able to compile assets. However, once we add a new gem to our Gemfile and run bundle install, then bundler ends up undoing this change and we're back to the same problem again...

Really hoping there's a better fix for this issue.

@cswilliams
Copy link

Just wanted to update that I was able to fix my issue by adding the following to my Gemfile:

gem 'google-protobuf', force_ruby_platform: true

I didn't realize this option could be set on a gem but it appears to work on the latest bundler. For anyone that also runs into this, setting force_ruby_platform via the BUNDLE_FORCE_RUBY_PLATFORM ENV var or via bundle config set (as the linked man page in the workaround comment suggests) breaks tailwindcss-rails (I assume because they don't offer a ruby platform version of their gem).

@hughevans
Copy link

It’s sub-optimal to have to compile all your gems from source (when adding force_ruby_platform: true anywhere in a Gemfile). So I’m tracking this now in #16853 as we need to work it out.

The very hack workaround I’m using right now is this:

bundle install
gem uninstall google-protobuf -a --force
gem install --platform ruby google-protobuf -v 3.25.3
sed -i 's/google-protobuf (3.25.3-aarch64-linux)/google-protobuf (3.25.3)/g' Gemfile.lock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants