Postgresql auto reconnect 2 #6654

Merged
merged 3 commits into from Jul 25, 2012

5 participants

@stevecj

Fixes not-quite-working PostgreSQL auto-reconnection on Connection#verify! and puts test coverage in place so that it should continue to work.

@rafaelfranca
Ruby on Rails member

Related with #6557.

@stevecj

Right. Based on feedback from #6557, I started again putting test coverage on the re-connect behavior that was supposed to be fixed by #6477. It turned out that was not quite working right because of an incompatible change to ...::PostgteSQLAdapter#translate_exception, and there had been no test coverage to reveal this problem.

@stevecj

Pulled master and rebased, and re-ran tests to keep the branch fresh.

Anyone going to accept this? I want to get it fixed on Edge, so I can proceed to get it fixed on the Rails versions used at the company I work for, where this will resolve an open issue that can affect our users.

@rafaelfranca
Ruby on Rails member

Could you squash the commits? I'll ask @tenderlove to review this.

@stevecj

Sure -- all 3 together, or just squash the warning fix?

It might be easier for me to cherry pick the commits onto other version branches if the other 2 are separate.I don't know if the change that c424ab0 fixes exists on the other branches.

@stevecj

While awaiting reply, I squashed the warning fix & force-pushed.

@stevecj

Ping.

@rafaelfranca
Ruby on Rails member
@tenderlove tenderlove was assigned Jun 11, 2012
@stevecj

Ping

@stevecj

Ping

@rafaelfranca
Ruby on Rails member

@stevecj Aaron is already assigned to this issue. He will take a look when he have some time.

@stevecj

OK -- thx for the update.

@andmej andmej and 1 other commented on an outdated diff Jun 21, 2012
...ord/test/cases/adapters/postgresql/connection_test.rb
+ CODE
+
+ begin
+ @connection.verify!
+ new_connection_pid = @connection.query('select pg_backend_pid()')
+ ensure
+ connection_class.class_eval <<-CODE
+ alias query query_unfake
+ undef query_fake
+ CODE
+ end
+
+ assert_equal original_connection_pid, new_connection_pid, "Should have a new underlying connection pid"
+ end
+
+ # Must have with_manual_interventions set to false for this
@andmej
andmej added a note Jun 21, 2012

Shouldn't this be "Must have with_manual_interventions set to true for this test to run"?

@stevecj
stevecj added a note Jun 21, 2012

Yes. I'll amend that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stevecj

Just rebased, re-ran tests & force-pushed to keep this fresh -- since it's been sitting here for quite a while.

@stevecj

Again, rebased & re-ran tests to keep the branch alive and fresh. Any chance of a pull some day?

@carlosantoniodasilva
Ruby on Rails member

@stevecj thanks for keeping this up-to-date with master, we surely appreciate. @tenderlove is aware of your pull request, it has already been discussed a few times, and it'll be probably merged in sooner or later. Thanks!

@carlosantoniodasilva carlosantoniodasilva and 1 other commented on an outdated diff Jul 3, 2012
...ord/test/cases/adapters/postgresql/connection_test.rb
+ # Fail with bad connection after next query attempt.
+ connection_class = class << @connection ; self ; end
+ connection_class.class_eval <<-CODE
+ def query_fake(*args)
+ if @called ||= false
+ @connection.stubs(:status).returns(PCconn::CONNECTION_BAD)
+ raise PGError
+ else
+ @called = true
+ @connection.unstub(:status)
+ query_unfake(*args)
+ end
+ end
+
+ alias query_unfake query
+ alias query query_fake
@carlosantoniodasilva
Ruby on Rails member

What's up with the spaces here? Can you check that (and the other below)?

@stevecj
stevecj added a note Jul 3, 2012

I think I tried them left_aligned, and thought it didn't read well, so kinda' made centered columns instead. I grant you that's pretty non-standard though. I'll fix those if you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Steve Jorgensen added some commits May 21, 2012
Steve Jorgensen Don't crash exception translation w/ nil result attribute.
Exception.result is nil when attempting a query after PostgreSQL
disconnect, resulting in new exception:
NoMethodError: undefined method `error_field' for nil:NilClass
0d63cda
Steve Jorgensen Simulated & actual (manual/skipped) PostgreSQL auto-reconnection tests. 6d5f4de
Steve Jorgensen Stop being silly with formatting of method aliasing. 4b1bca0
@stevecj

I just fixed the silly formatting, per Carlos' comment & rebased onto the latest master.

Anything else I can do to help move this along?

@tenderlove tenderlove merged commit 0dc356e into rails:master Jul 25, 2012
@stevecj

Thanks :)

@johnnypez

Will this be backported to Rails 3.2.x?

@tenderlove
Ruby on Rails member

If someone is willing to do the work, yes. I think there are other commits than this pull request for the bug to be fixed on 3-2-stable though.

@stevecj

FWICS, the bug that this fixes does not actually exist on the 3.x branches. The bug that was fixed by #6477 does though, so that's the fix that needs to be backported.

The test coverage from here would be helpful in preventing further regressions of psql reconnection functionality regardless of the cause, and so might be useful to backport. Please note, however, that I badly mangled the first of those tests, and subsequently mangled my initial attempt at fixing it, which I rushed through due to my embarrassment at the initial test mangling. Therefore, also see #7292 and #7294.

I can probably be available to work this back-porting, but it could take me a week or 3 to squeeze it into my schedule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment