Rails 6: `connection_pool.rb` segmentation faul

Apologies in advance if I’m not posting this in the right place. I am encountering a peculiar segmentation fault error while attempting to access a Rails 6.0.6 app.

When I execute rails s and try to access the root path on localhost, the number of errors in the console is too numerous to capture here. I have recorded them using rails s &> err.log. In that file I can observe the following errors:

=> Booting Puma
=> Rails 6.0.6 application starting in development
=> Run `rails server --help` for more startup options
[3163] Puma starting in cluster mode...
[3163] * Puma version: 5.6.4 (ruby 2.7.8-p225) ("Birdie's Version")
[3163] *  Min threads: 5
[3163] *  Max threads: 5
[3163] *  Environment: development
[3163] *   Master PID: 3163
[3163] *      Workers: 2
[3163] *     Restarts: (✔) hot (✖) phased
[3163] * Preloading application
[3163] * Listening on
[3163] * Listening on http://[::1]:3000
[3163] Use Ctrl-C to stop
[3163] - Worker 0 (PID: 3184) booted in 0.0s, phase: 0
[3163] - Worker 1 (PID: 3185) booted in 0.0s, phase: 0
source=rack-timeout id=128022b8-ca22-44ed-9cda-f214b42540ab timeout=123000ms state=ready
Started GET "/" for at 2023-06-12 19:41:30 +0700
source=rack-timeout id=128022b8-ca22-44ed-9cda-f214b42540ab timeout=123000ms service=1ms state=active
/Users/me/.rvm/gems/ruby-2.7.8/gems/activerecord-6.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:337: [BUG] Segmentation fault at 0x000000011026cade
ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [arm64-darwin22]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.
Don't forget to include the above Crash Report log file in bug reports.

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0013 e:000012 CFUNC  :sleep
c:0002 p:0016 s:0008 e:000007 BLOCK  /Users/me/.rvm/gems/ruby-2.7.8/gems/activerecord-6.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:3 [FINISH]
c:0001 p:---- s:0003 e:000002 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
/Users/me/.rvm/gems/ruby-2.7.8/gems/activerecord-6.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:337:in `block in spawn_thread'
/Users/me/.rvm/gems/ruby-2.7.8/gems/activerecord-6.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:337:in `sleep'

-- Other runtime information -----------------------------------------------

* Loaded script: puma: cluster worker 1: 3163 [octopi]

* Loaded features:

    0 enumerator.so
    1 thread.rb
    2 rational.so
    3 complex.so
    4 ruby2_keywords.rb
    5 /Users/me/.rvm/rubies/ruby-2.7.8/lib/ruby/2.7.0/arm64-darwin22/enc/encdb.bundle
    6 /Users/me/.rvm/rubies/ruby-2.7.8/lib/ruby/2.7.0/arm64-darwin22/enc/trans/transdb.bundle
    7 /Users/me/.rvm/rubies/ruby-2.7.8/lib/ruby/2.7.0/arm64-darwin22/rbconfig.rb
    8 /Users/me/.rvm/rubies/ruby-2.7.8/lib/ruby/2.7.0/rubygems/compatibility.rb
    9 /Users/me/.rvm/rubies/ruby-2.7.8/lib/ruby/2.7.0/rubygems/defaults.rb

The output is very large so I can’t paste it all here. However, it seems like the issue is coming from:

/Users/me/.rvm/gems/ruby-2.7.8/gems/activerecord-6.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:337: [BUG] Segmentation fault at 0x000000011026cade

I suspect this has something to do with ActiveRecord / PostgreSQL but I can’t seem to figure out the problem. If I run a Rails console, I can do the following:

2.7.8 :001 > puts "Hello"

So that’s fine. The issue seems to happen when accessing the database:

User.first # This causes a segfault

After a lot of Googling, I’ve managed to get the app working if I use the following setting in databases.yml:

  host: <%= ENV['DATABASE_HOST'] %>
  adapter: postgresql
  encoding: unicode
  database: <%= ENV['DATABASE_NAME'] %>
  pool: 5
  gssencmode: disable

That gssencmode: disable seems to do the trick. However, it’s not a setting that seems reasonable to keep as I believe it disables the encryption mode used for GSSAPI authentication.

I am running a Homebrew managed postgresql@12 version.

Expected behavior

Should be able to run the Rails server and access the database without any issues

Actual behavior

App segfaults unless I use gssencmode: disable in databases.yml

System configuration

Rails version: 6.0.6 Ruby version: 2.7.8 PostgreSQL version: 12.15 OS: MacOS Ventura 13.4 - MacBook Pro (M1 chip)

GSS-API support for Postgres was first made available in v 12. There have been some bugfixes implemented in future versions of Postgres.

While setting the mode to disabled will not allow you to set up a GSS-API authentication mechanism (which is used in cases where you authenticate using a Kerberos solution), communication with the server can still be encrypted with TLS.