Subject: | crasher involving uncommitted exit |
Date: | Fri, 30 Nov 2018 13:18:25 +1100 |
To: | bug-DBD-Pg [...] rt.cpan.org |
From: | AP <cpan20181130 [...] ta.grue.cc> |
Hi,
I've made a test case so I'll let it speak for itself (mostly) :)
The following code crashes if the script is exited without a commit. From
memory, long and distant now, my script crashed in other ways but this is
what I can reproduce and the rest is unclear memory.
The code is run under Debian stretch with a perlbrew'd perl of 5.28. Postgres
versions involved:
ii libpq5:amd64 11.1-1.pgdg90+1 amd64 PostgreSQL C client library
ii postgresql-10 10.6-1.pgdg90+1 amd64 object-relational SQL database, version 10 server
This is, obviously, a vastly simplified version of what I'm doing. :)
code:
--- 8< ---
#!/usr/bin/env perl
use DBI;
use DBD::Pg;
use strict;
use warnings;
use v5.20;
say " perl ver: ".$];
say " DBI ver: ".$DBI::VERSION;
say "DBD::Pg ver: ".$DBD::Pg::VERSION;
say 'connect';
my $dbh = DBI->connect("DBI:Pg:database=db", "user", "pass", { AutoCommit => 0 });
say 'select';
$dbh->do('SELECT 1;');
say 'jump ship';
--- 8< ---
end result:
--- 8< ---
perl ver: 5.024001
DBI ver: 1.642
DBD::Pg ver: 3.7.4
connect
select
LOG: duration: 0.077 ms statement: begin
LOG: duration: 0.326 ms statement: SELECT 1;
jump ship
Issuing rollback() due to DESTROY without explicit disconnect() of DBD::Pg::db handle dbname=mdstash at ./bin/testdodgy.pl line 22.
Attempt to free unreferenced scalar: SV 0x55fe900fce48, Perl interpreter: 0x55fe8fee0010 at ./bin/testdodgy.pl line 22.
Segmentation fault
--- 8< ---
The only thing that stops the crash is an explicit COMMIT or ROLLBACK
before exit.
ie: the following can be added after the jump ship and no crash will result.
--- 8< ---
$dbh->do('ROLLBACK;');
--- 8< ---
Hope this helps. Not sure what more to add so please shout if you require
more info.
AP.