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

Missing connection attribute on PG::ConnectionBad error #461

Closed
ahjmorton opened this issue Jun 10, 2022 · 0 comments
Closed

Missing connection attribute on PG::ConnectionBad error #461

ahjmorton opened this issue Jun 10, 2022 · 0 comments

Comments

@ahjmorton
Copy link

Hi there,

I'd like to report a bug / some unexpected behaviour we've observed in the 1.3.5 version of the gem. If this is expected / documented somewhere that I've missed, apologies and please point me at it.

Test case

Below we're using ActiveRecord to orchestrate the connection to Postgres using the ruby-pg gem under the hood.

If we execute the following:

error = 
      begin
        ActiveRecord::Base.connection.
          execute("select pg_terminate_backend(pg_backend_pid());")
      rescue ActiveRecord::StatementInvalid => e
        return e
      end

# connection_bad_error will be an instance of `PG::ConnectionBad`
connection_bad_error = error.cause

puts connection_bad_error.connection

What I would expect to happen

I'd expect that the connection attribute on the exception to be present as we should know which connection tried to delete it's own backend.

This is the behaviour the library had up until 1.2.3.

What actually happens

The connection attribute is missing so puts connection_bad_error.connection prints nil.

I'm not sure if other cases of PG::ConnectionBad would cause the connection attribute to be included.

Why is this important

If we detect a connection is had we may want to remove it from the AR connection pool / do some other cleanup action that we're unable to do as we don't know which connection is bad.

@ahjmorton ahjmorton changed the title Missing connection attribute on PG::ConnectionBad Missing connection attribute on PG::ConnectionBad error Jun 10, 2022
larskanis added a commit to larskanis/ruby-pg that referenced this issue Jun 14, 2022
.. in various places where it was missing.

Fixes ged#461
larskanis added a commit to larskanis/ruby-pg that referenced this issue Jun 14, 2022
.. in various places where it was missing.

Fixes ged#461
larskanis added a commit to larskanis/ruby-pg that referenced this issue Jun 14, 2022
.. in various places where it was missing.

Fixes ged#461
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant