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

Crash #291

Closed
ged opened this issue Jan 20, 2019 · 18 comments
Closed

Crash #291

ged opened this issue Jan 20, 2019 · 18 comments
Labels
1.1.4 bug Library major migrated Migrated from issues on Bitbucket and/or Rubyforge

Comments

@ged
Copy link
Owner

ged commented Jan 20, 2019

Original report by Yosi Attias (Bitbucket: yosiat, GitHub: yosiat).


Hi,

I have crashes started since I upgraded my postgres to 11 (via Homebrew)

This is stack trace:

/Users/yosi/code/rails_project/vendor/bundle/ruby/2.6.0/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/Users/yosi/code/rails_project/vendor/bundle/ruby/2.6.0/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/Users/yosi/code/rails_project/vendor/bundle/ruby/2.6.0/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'

I failed to reproduce it to minimal test case.

Please let me know which information I can supply to help resolve this issue.

@ged
Copy link
Owner Author

ged commented Jan 21, 2019

Original comment by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).


Only the ruby level stack trace is complete, but not the C level trace. So we know that the segfault is somewhere in PG::Connection.new but not more. It could be that some of the libraries changed it's ABI while updating, so that you need to rebuild the pg gem. Try

gem pristine pg

Segfaults while connection can also be a result of changed OpenSSL versions.

If this doesn't work, a valgrind output would be useful and a minimal example.

@ged
Copy link
Owner Author

ged commented Jan 23, 2019

Original comment by Yosi Attias (Bitbucket: yosiat, GitHub: yosiat).


Thanks,
I will that gem pristine pg and will update.

How can I get a valgrind output if the issue persists?

@ged
Copy link
Owner Author

ged commented Jan 26, 2019

Original comment by Yosi Attias (Bitbucket: yosiat, GitHub: yosiat).


Hi,

Sadly the issue still persists after bundle pristine

@ged ged modified the milestone: Pending Oct 8, 2019
@ged ged added the migrated Migrated from issues on Bitbucket and/or Rubyforge label Oct 8, 2019
@jeffmoss
Copy link

@ged did you find a solution to this?

@larskanis
Copy link
Collaborator

Unfortunately the stack trace is less expressive, further information wasn't posted and no solution was found. So I think there's no way to go and we can close the ticket.

@srini91
Copy link

srini91 commented Nov 30, 2019

FWIW, does look like a bug; noted here separately by another user on stack overflow:
https://stackoverflow.com/questions/59089991/ruby-2-6-5-and-postgresql-pg-gem-segmentation-fault

@philsmy
Copy link

philsmy commented Dec 2, 2019

I am the person who posted the bug on stackoverflow. This bug happens to me ONLY in rails console. Running under Puma in dev, or Passenger in production mode works fine.

I 'fixed' it for a couple of days by replacing my database.yml file with the default one coming from a test application. But, without any changes to that file, it has stopped working again. I have uninstalled and reinstalled both postgresql and the pg gem.
I am on a mac running homebrew and I have tried both putting gem 'pg' in the gemfile and doing the gem install pg -- --with-pg-config=/usr/local/bin/pg_config.
All to no effect.

Incredibly, on the same machine - so pointing to the same postgresql, and using the same version (1.1.4) of the gem, though in a different bundle - I CAN access the database from the command line from inside rails console of the test app (literally just create a new app, create a model).

To me, this means there is a configuration issue or a conflict between perhaps another gem or something.

My database.yml looks like this:

default: &default
  adapter: postgresql
  encoding: unicode
  # pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  host: localhost
  database: myproject_development

test:
  <<: *default
  host: localhost
  database: myproject_test

production:
  url: <%= ENV['DATABASE_URL'] %>

I am uploading the stack trace.
pg-gem-crash.txt

I am giving up and moving my project over to mysql. This is my first time to use postgresql - after 15 years of rails/mysql (yes, I started at rails 0.9!).

@cbandy
Copy link
Contributor

cbandy commented Dec 2, 2019

If I'm reading correctly, I see the last call in libpq is pg_GSS_have_cred_cache. Possibly related to https://bugs.ruby-lang.org/issues/16239? Which arrived at the ML: https://postgr.es/m/16041-b44f9931ad91fc3d%40postgresql.org.

@tadast
Copy link

tadast commented Dec 2, 2019

I'm getting this too. In case it helps:
It fails consistently with both pg-1.1.3 and 1.1.4, only in a rails console when I invoke anything ActiveRecord related. Fails on both postgresql 12 and 11 versions. I use homebrew.

It has started happening after ran brew upgrade, before that pg-1.1.4 was working fine. Tried reinstalling ruby (via rbenv), postgres and the gem - nothing helps. Perhaps it's one of the dependencies that got updated by homebrew?

@jrun
Copy link

jrun commented Dec 2, 2019

I'll add my experience here in case it helps. I'm also experiencing a crash from ActiveRecord after upgrading to PostgreSQL 12 via Homebrew.

I "fixed" the problem by brew installing postgresql@9.6. Then reinstalling the pg gem. I didn't dig deeper but I'm guessing the pg gem must just happen to compile with a compatible libpq.

My Rails app is working fine with PostgreSQL 12 since.

@cbandy
Copy link
Contributor

cbandy commented Dec 3, 2019

pg_GSS_have_cred_cache was added in PostgreSQL 12 circa Apr 2019. The crash reported by OP is with PostgreSQL 11.

@tadast, @jrun, this information is helpful, but I think we should track these separately. If you can, please open a new issue with a log of your crash including the C level backtrace information. Thanks!

@philsmy
Copy link

philsmy commented Dec 3, 2019

I'll add my experience here in case it helps. I'm also experiencing a crash from ActiveRecord after upgrading to PostgreSQL 12 via Homebrew.

I "fixed" the problem by brew installing postgresql@9.6. Then reinstalling the pg gem. I didn't dig deeper but I'm guessing the pg gem must just happen to compile with a compatible libpq.

My Rails app is working fine with PostgreSQL 12 since.

@jrun I don't quite understand your last line...if you brew install postgresql@9.6, isn't your app running on 9.6 and not 12?
For me, it is a matter of matching up dev and production at least using the same database if not the same version!
I have just clean installed a new macos 10.14 and will see if I get the issue.

@philsmy
Copy link

philsmy commented Dec 3, 2019

Sorry if I am spamming this thread. Anyway, I did a completely clean install (i.e. reformatted hard drive) of MacOS 10.14 Mojave. I did nothing 'fancy', just installed homebrew and rbenv. I installed postgresql by brew install postgresql.
There is only one thing 'different' that I did, and this came from a GoRails post about getting your environment running. They said
"Mojave changed the location of header files necessary for compiling C extensions. You might need to run the following command to install pg, nokogiri, or other gems that require C extensions:"

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

I ran that.

cd'ed into my project directory, did build install, and....everything worked fine.
I can rails c and do a MyModel.new without getting the segfault.

Now, that being said, this has 'worked fine' before. See my comment above that in one rails app I could do ActiveRecord from within rails console while in another app I could not. So we shall see what happens over time.

If it helps, here is a list of the brews I have installed with their versions.

$ brew list --versions
autoconf 2.69
cairo 1.16.0_2
fontconfig 2.13.1
freetype 2.10.1
gdbm 1.18.1
gettext 0.20.1
glib 2.62.3
gobject-introspection 1.62.0
icu4c 64.2
jpeg 9c
libffi 3.2.1
libpng 1.6.37
libtiff 4.1.0
little-cms2 2.9
lzo 2.10
node 13.2.0
nspr 4.23
nss 3.47.1
openjpeg 2.3.1
openssl@1.1 1.1.1d
pcre 8.43
pixman 0.38.4
pkg-config 0.29.2
poppler 0.81.0
postgresql 12.1
python 3.7.5
qt 5.13.2
rbenv 1.1.2
readline 8.0.1
ruby-build 20191124
sqlite 3.30.1
xz 5.2.4
yarn 1.19.2

@cbandy
Copy link
Contributor

cbandy commented Dec 3, 2019

@philsmy I'm not able to reproduce your segfault, but I do see some other behavior related to macOS fork() that is mitigated by adding gssencmode: disable to the default section of database.yml.

@tadast, @jrun, if you are able can you try that in your setups with postgresql 12?

@jeffmoss
Copy link

jeffmoss commented Dec 3, 2019

My temporary workaround for this was to brew install postgresql version 11, compile the pg gem, then brew install postgresql version 12 and (re)start the server.

Now I've got a client gem compiled with version 11 code that doesn't segfault, and a server running the latest version 12 code.

@jrun
Copy link

jrun commented Dec 3, 2019

@cbandy I can confirm that adding gssencmode: disable to database.yml resolves the crash that I was experiencing.

@cbandy
Copy link
Contributor

cbandy commented Dec 3, 2019

Thanks @jrun. Let's continue any discussion of a 12 crash that is avoided by gssencmode: disable in #311.

@tadast
Copy link

tadast commented Dec 4, 2019

Adding gssencmode: disable has resolved the segfault to me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.1.4 bug Library major migrated Migrated from issues on Bitbucket and/or Rubyforge
Projects
None yet
Development

No branches or pull requests

8 participants