Fixup for a possible deadlock if db.env.BeginTxn fails (#516)

* attempt to fix the deadlock

* slightly more correct check

Co-authored-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Igor Mandrigin 2022-07-07 08:52:30 +02:00 committed by GitHub
parent a86baf3e81
commit 95e361fa1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -402,6 +402,11 @@ func (db *MdbxKV) BeginRo(ctx context.Context) (txn kv.Tx, err error) {
if err == nil {
db.wg.Add(1)
}
if txn == nil {
// on error, or if there is whatever reason that we don't return a tx,
// we need to free up the limiter slot, otherwise it could lead to deadlocks
<-db.roTxsLimiter
}
}()
tx, err := db.env.BeginTxn(nil, mdbx.Readonly)