Skip to content

Commit

Permalink
Merge pull request #6584 from ehuelsmann/fixes/master/rollback-on-error
Browse files Browse the repository at this point in the history
Fix response status code check
  • Loading branch information
ehuelsmann committed Jun 25, 2022
2 parents 05af552 + 5b78b0b commit 5c8154b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions bin/ledgersmb-server.psgi
Expand Up @@ -67,6 +67,11 @@ else {
}
Log::Any::Adapter->set('Log4perl');

# Make sure to get the correct logging order on console logging
# (which mixes request logging with Log4perl logging)
STDOUT->autoflush(1);
STDERR->autoflush(1);

LedgerSMB::PSGI::setup_url_space(
development => ($ENV{PLACK_ENV} eq 'development'),
);
Expand Down
18 changes: 13 additions & 5 deletions lib/LedgerSMB/Middleware/MainAppConnect.pm
Expand Up @@ -191,16 +191,24 @@ sub call {
if ($dbh and $dbh->{Active}) {
$dbh->rollback;
$dbh->disconnect;
$log->warn('Unexpected exit; rolling back current db transaction');
}
};
return Plack::Util::response_cb(
$self->app->($env), sub {
if ($dbh and $dbh->{Active}
and not is_server_error($_[0])) {
$env->{__app_guard__}->dismiss;
$dbh->commit;
$log->info("Server response: $_[0]->[0]");
if ($dbh and $dbh->{Active}) {
if (is_server_error($_[0]->[0])) {
$dbh->rollback;
$log->info('Rolling back current db transaction');
}
else {
$dbh->commit;
$log->debug('Committing current db transaction');
}
$dbh->disconnect;
}
$env->{__app_guard__}->dismiss;
}
});
}

Expand Down

0 comments on commit 5c8154b

Please sign in to comment.