Skip to content

segfault with macos precompiled binary when using with rails spring #663

@timdiggins

Description

@timdiggins

Firstly, thanks very much for the gem! And also note there's a workaround for this issue below.

I'm using pg gem in a rails project (7.1.x) with ruby 3.4.x.
When upgrading to 1.6.1 from 1.5.9 everything works fine on linux (CI/server) but on my local development mac (Macos 15.6, ARM) I get segfaults unless I disable spring, or set OBJC_DISABLE_INITIALIZE_FORK_SAFETY.

Simplest way I can repro this is (with a rails project with pg and spring and some rspec that exercises database):

spring stop && rspec spec/lib/some_spec.rb

output is:

Spring stopped.
Running via Spring preloader in process 56650
objc[56650]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[56650]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

This happens on mine and a colleague's machine. Note that it happens with any rails command that uses spring.

This only occurs with the standard binary - if I replace this with source (see workaround) and allow it to be compiles then it works as before.

This is specific segfault is a well-known problem in ruby and if I understand correctly needs to be addressed in each gem. Don't know why it would compile locally without problem but not with precompiled version.

Refs

Workaround:

Use ruby source version rather than precompiled binary (see README.md) or if using bundler need to manually replace (in Gemfile.lock):

   pg (1.6.1-arm64-darwin)

with

    pg (1.6.1)

(I prefer this workaround to setting OBJC_DISABLE_INITIALIZE_FORK_SAFETY or disabling spring).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions