private/dbutil: rollback pending transactions on panic

We don't do a lot of panicking in our main code, so hopefully this won't
matter much, but we /do/ call panic a lot in our tests (t.Fatal,
require.NoError, etc). And when that happens, we need pending
transactions to be aborted or we can get into a deadlock situation when
something else tries to /Close/ that connection.

Change-Id: Idaf0d543ac95afea34f9b2393d1187f5322e9f0f
This commit is contained in:
paul cannon 2020-01-23 09:58:09 -06:00
parent cadd727df8
commit fd84fa6316

View File

@ -36,6 +36,11 @@ func ExecuteInTx(ctx context.Context, dbDriver driver.Driver, tx txLike, fn func
return crdb.ExecuteInTx(ctx, tx, fn)
}
defer func() {
if x := recover(); x != nil {
// does nothing if tx is already rolled back or committed.
_ = tx.Rollback()
panic(x)
}
if err == nil {
err = tx.Commit()
} else {