Skip to content

Commit

Permalink
Properly discover a connection is closed in postgresql_adapter
Browse files Browse the repository at this point in the history
PQstatus doesn't properly test if future operations will succeed. A
PQping function is added to libpq in PostgreSQL 9.1, but if we rely
on it, everyone on earlier versions of Postgres is out of luck,
and the pg gem wouldn't have the 'fix' until the next release.

Thanks to @cbrecabarren and @ged for handling all the dirty details.

Closes #3392.
  • Loading branch information
steveklabnik committed May 24, 2012
1 parent abccf82 commit 4dacac3
Showing 1 changed file with 2 additions and 1 deletion.
Expand Up @@ -457,7 +457,8 @@ def clear_cache!

# Is this connection alive and ready for queries?
def active?
@connection.status == PGconn::CONNECTION_OK
@connection.query 'SELECT 1'
true
rescue PGError
false
end
Expand Down

1 comment on commit 4dacac3

@ghazel
Copy link
Contributor

@ghazel ghazel commented on 4dacac3 Oct 17, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why @connection.query instead of @connection.async_exec?

Please sign in to comment.