Rails 4 ActiveRecord throws PG :: UnableToSend on Ubuntu 13.04

We have a Ruby v.2.0.0-p247 on Rails v4.0.1 using pg gem v0.17.0 .

The application runs smoothly under Mac OS X Mavericks v10.9 with PostgreSQL Server v9.2.4 installed using HomeBrew , but in Ubuntu v13.04 it throws the following exception using PostgreSQL Server 9.1 :

PG::UnableToSend: server closed the connection unexpectedly

This probably means the server terminated abnormally before or while processing the request.

An exception occurs after transactional requests (form submission).

I tried the following with database.yml :

  • Adding reconnect: true
  • Adding port: 5432
  • Adding socket: /var/run/postgresq/SOCKET_FILE

And tried the following with PostgreSQL configuration in Ubuntu:

  • Disabling SSL.
  • Change TCP keepalives settings to disable timeout.
  • Changing the log level to DEBUG and looking for possible errors on the PostgreSQL server.

Also tried:

  • Switch to pg gem v0.16.0.
  • Update all Ubuntu 13.04 packages to the latest versions.

What could be wrong?

UPDATE:

03/12/2013: Some suggested checking the firewall settings. ufw status said ufw disabled. 08/12/2013: After testing with the vanilla Rails application and a lot with the current application, the problem arises from the rails4/activerecord-session_store gem. Line 47 in lib/active_record/session_store/session.rb is the culprit.

+8
ruby ruby-on-rails activerecord postgresql ubuntu
source share
4 answers

This basically happens when you use the old version of launchy , and according to this issue when you run git repo quoting @infertux

In the rare case when exec cannot run a command - usually when a file cannot be opened, raising Errno::ENOENT - Launchy will throw an exception but not show any output

You can check Gemfile.lock to see if you are using letter_opener version launchy than 2.4.1, and I doubt that you are using letter_opener Gem in your development environment, which depends on launchy so updating letter_opener to 1.2.0 will update launchy to version above 2.4.0 is basically 2.4.2, which fixes this problem.

All loans go to @infertux

+4
source share

This will really help if you provided your database.yml file

The default connection method is a unix domain socket, which should not be confused with a TCP / IP socket. By default, the unix domain socket connection method is used.

You must verify that the unix user you are trying to run the rails has sufficient permissions to access the domain juice (usually in /var/run/postgresql/.s.PGSQL.5432 )

Try entering the following as the user of the rails:

 psql 

If you get a database connection error, then this is most likely a permission problem if postgres is actually running.

You can check your /etc/postgresql.conf file and configure the postgres group and socket permissions at startup:

 unix_socket_directory = '/var/run/postgresql' # dont worry if yours is different #unix_socket_group = '' # default is usually ok #unix_socket_permissions = 0777 # uncomment this if needed 

Another option is to add the user to the group that has write access to the socket, and also allow all users on the computer to access the permission settings 0777 above. You can create a postres_users group for this purpose if, by default, Ubuntu groups provide insufficient granularity for your needs.

+1
source share

It seems to me that there is confusion in the connection method. PostgreSQL supports two methods:

  • Connector
  • TCP / IP

It is completely, completely different .:-)

In your question, you show the socket parameter, but mention TCP. I suggest focusing on each of these two connection methods individually and see what gives the results. Ie, create two branches of the pg-socket and pg-tcpip so that everything is clear. Then clear the configuration file and try to connect using both methods.

Often connecting sockets is easier because you just need to know the path to the socket file. No fireware settings are needed (because there is no TCP / IP connection).

Update your question after this and tell how each of these two methods did for you.

0
source share

All Articles