bucardo / dbdpg

Perl Postgres driver DBD::Pg aka dbdpg
48 stars 36 forks source link

Result of a commit should be checked before re-enabling AutoCommit and disabling BegunWork #40

Closed oschwald closed 5 years ago

oschwald commented 6 years ago

Currently, if a commit fails, you can end up in a situation where you are inside of a transaction even though DBD::Pg believes otherwise. This is because DBicf_AutoCommit is set to 1 and DBIcf_BegunWork is set to 0 before the commit is even executed:

https://github.com/bucardo/dbdpg/blob/3f277a5993ed339c604140e814811a67ecbdb79f/dbdimp.c#L593-L603 This has happened to us several times in production when doing something like:

$dbh->begin_work;
$dbh->do( 'SET LOCAL statement_timeout TO ?', {}, $timeout );
...
$dbh->commit;

If the timeout happens during the commit, you may end up in this invalid state.

turnstep commented 5 years ago

So I'm thinking a simple fix like this might help 81b518137a08a0db9bfbd1ceb0179b474e06afca

Cannot think of a way to write a test for this at the moment, as 'commit' is baked into Postgers and hard to mock.

turnstep commented 5 years ago

Now part of version 3.10.0