typhoeus / ethon

Very simple libcurl wrapper.
MIT License
137 stars 139 forks source link

[BUG] Segmentation fault at ethon-0.16.0/lib/ethon/easy/operations.rb:30 #234

Open ValentinoRusconi-EH opened 1 year ago

ValentinoRusconi-EH commented 1 year ago

I get the following seg fault:

c:0153 p:---- s:1033 e:001032 CFUNC  :easy_perform
c:0152 p:0007 s:1028 e:001027 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/ethon-0.16.0/lib/ethon/easy/operations.rb:30
c:0151 p:0013 s:1024 e:001023 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/typhoeus-1.4.0/lib/typhoeus/request/operations.rb:16
c:0150 p:0025 s:1019 e:001018 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/typhoeus-1.4.0/lib/typhoeus/request/cacheable.rb:18
c:0149 p:0018 s:1014 e:001013 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/typhoeus-1.4.0/lib/typhoeus/request/block_connection.rb:31
c:0148 p:0033 s:1010 e:001009 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/typhoeus-1.4.0/lib/typhoeus/request/stubbable.rb:25
c:0147 p:0012 s:1005 e:001004 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/typhoeus-1.4.0/lib/typhoeus/request/before.rb:26
c:0146 p:0028 s:1001 e:001000 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/typhoeus-1.4.0/lib/typhoeus/adapters/faraday.rb:82
c:0145 p:0012 s:0996 e:000995 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/typhoeus-1.4.0/lib/typhoeus/adapters/faraday.rb:72
c:0144 p:0012 s:0991 e:000990 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/faraday-1.10.3/lib/faraday/rack_builder.rb:154
c:0143 p:0040 s:0985 e:000984 METHOD /Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/faraday-1.10.3/lib/faraday/connection.rb:516

# -- Ruby level backtrace information ----------------------------------------
/Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.0.2/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
/Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.0.2/lib/puma/server.rb:232:in `block in run'
/Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.0.2/lib/puma/server.rb:429:in `process_client'
/Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.0.2/lib/puma/request.rb:92:in `handle_request'
/Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.0.2/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
/Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.0.2/lib/puma/request.rb:93:in `block in handle_request'
/Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.0.2/lib/puma/configuration.rb:268:in `call'
/Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-6.1.7.4/lib/rails/engine.rb:539:in `call'
/Users/valentino/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rack-cors-1.1.1/lib/rack/cors.rb:100:in `call'
# DiagnosticReports
  "vmRegionInfo" : "0xdac11530 is not in any region.  Bytes before following region: 628992720\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      __TEXT                      1003ec000-1003f0000    [   16K] r-x\/r-x SM=COW  ...s\/USER\/*\/ruby",
  "exception" : {"codes":"0x0000000000000105, 0x00000000dac11530","rawCodes":[261,3670086960],"type":"EXC_BAD_ACCESS","signal":"SIGABRT","subtype":"UNKNOWN_0x105 at 0x00000000dac11530"},
  "vmregioninfo" : "0xdac11530 is not in any region.  Bytes before following region: 628992720\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      __TEXT                      1003ec000-1003f0000    [   16K] r-x\/r-x SM=COW  ...s\/USER\/*\/ruby",
  "asi" : {"CoreFoundation":["*** multi-threaded process forked ***"],"libsystem_c.dylib":["crashed on child side of fork pre-exec"]},
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 7,

Chip: Apple M2 Max OS: Ventura 13.4.1

Geesu commented 1 year ago

Seeing this on macOS 13.4 (22F66). Intel. Ruby 2.7.6 and ruby 3.2.2. curl 7.88.1

Nodalailama commented 1 year ago

Same here; macOS 13.4.1 (22F82) M1. Ruby 3.0.3.

ValentinoRusconi-EH commented 1 year ago

We we're facing this segfault using chewy. Until a solution is found we patched the net adapter like so:

  Chewy.settings = {
    host: 'localhost:9200'
  }.tap do |config|
      config[:transport_options] = {
        proc: ->(f) { f.adapter :net_http }
      }
  end

not recommended to use it in prod.

mshwery commented 1 year ago

I started getting this only after updating my system to macOS 13.5 (22G74) (from 13.4), M1, Ruby 3.2.2

Notably it only seems to happen (or at least I've only caught it) when running our test suite.

When I disable parallelization entirely (config.active_support.test_parallelization_threshold = some_arbitrarily_high_value) I do not encounter this crash, of course.

paniko0 commented 1 year ago

Same issue here. I have just migrated from an Intel Mac to an M2 and been facing this issue. Updating ethon to 0.16.0 which used to be the solution doesn't seem to be working anymore.

Ruby 2.7.6 Ventura 13.5

timherby commented 1 year ago

I'm experiencing the same crash on M2 Mac using native ARM architecture when running the code in Resque, which forks the process for every job.

-- Control frame information -----------------------------------------------
c:0077 p:---- s:0408 e:000407 CFUNC  :easy_perform
c:0076 p:0062 s:0403 E:000390 METHOD /Users/timherby/.rvm/gems/ruby-2.7.7/gems/ethon-0.16.0/lib/ethon/easy/operations.rb:30

I originally thought it was due to ethon/curls/functions.rb and ethon/curls/settings.rb getting initialized, but I have confirmed it still happens even if I use require:false for both Typhoeus and Ethon and they are not loaded in the parent process (also confirmed).

I've also reinstalled curl, ffi, libffi, and openssl, with no luck, it's still crashing. I've linked the thread above where I'm looking to abandon the use of Typhoeus and Ethon as it appears there is no energy behind fixing these segmentation faults that are plaguing the library on new macs: https://github.com/search?q=repo%3Atyphoeus%2Fethon+Segmentation+Fault&type=issues

I'd love to help troubleshoot if anyone wants to reach out and collaborate on this.

edalorzo commented 11 months ago

Not sure if this would help anyone else. I was running into segfaults in this way as well, while trying to run it from MacOS Monterey using the Apple M1 Pro chip. I discovered that if I changed my puma settings to run in standalone mode (PUMA_WORKERS=0) the application would run without issues. Clearly, not a solution to the problem, but at least a workaround for testing and debugging purposes. In my team other people told me they have build ruby using Rosetta and that has solved the issue for them as well.

lauraBaakman commented 9 months ago

Seeing this on macOS 14.1.1 (23B81). Intel. Ruby 3.2.2, curl 8.4.0

➜ curl --version
curl 8.4.0 (x86_64-apple-darwin23.0.0) libcurl/8.4.0 (SecureTransport) OpenSSL/3.2.0 zlib/1.2.12 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.4 libssh2/1.11.0 nghttp2/1.58.0 librtmp/2.3 OpenLDAP/2.6.6
Release-Date: 2023-10-11
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz MultiSSL NTLM SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

Update

Disabling Spring: DISABLE_SPRING=true solved it for me.

nettofarah commented 9 months ago

I'm also seeing the issue on macOS 13.6.1 (22G313), Ruby 3.2.2 and curl 8.4.0. This is an Intel Mac, so I don't think this issue is exclusive to M1.

Melhaya commented 9 months ago

Same here: macOS M1 Sonoma 14.1.2, Ruby 3.2.2 and Curl 8.1.2 (x86_64-apple-darwin23.0)

Aubermean commented 8 months ago

My issues are on Alpine with docker rather than Mac. Try:

  1. bundle config build.ffi --enable-libffi-alloc
  2. ffi newest release with forced build: gem 'ffi', github: 'ffi/ffi', submodules: true, force_ruby_platform: true
  3. the ethon branch/PR related to thread safe easy handle cleaup
hardikhappy commented 3 months ago

Hi Folks, Is there any work going on to fix the issue or any workaround for it? As I am also facing the same issue, for Ruby version 2.5.8 and Rails 5.0.7 with Ubuntu 22.04.3 LTS.

biot023 commented 2 months ago

Seeing this in Ubuntu 24.04 with Ruby 2.7.8 and ethon 0.16.0 Not seeing any commits on this project for nearly a year and a half so I guess we're stuffed on this issue. Hopefully updating Ruby will sort it, although some of the comments above suggest it might not.

manishaodedara2589 commented 1 month ago

Facing same issue in Ubuntu 22.04.4 LTS (GNU/Linux x86_64) with Ruby 2.7.8 and ethon 0.16.0

ethon-0.16.0/lib/ethon/easy/operations.rb:30: [BUG] Segmentation fault at 0x00007ad7ebef3140
ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0041 p:---- s:0252 e:000251 CFUNC  :easy_perform
Aubermean commented 3 weeks ago

My issues are on Alpine with docker rather than Mac. Try:

  1. bundle config build.ffi --enable-libffi-alloc
  2. ffi newest release with forced build: gem 'ffi', github: 'ffi/ffi', submodules: true, force_ruby_platform: true
  3. the ethon branch/PR related to thread safe easy handle cleaup

This could be your solution, as it was mine. Otherwise, you can also try moving from Ruby 2.7.8 to Ruby 3.