diff --git a/kv/mdbx/kv_mdbx.go b/kv/mdbx/kv_mdbx.go index ec70f5d25..1aae79097 100644 --- a/kv/mdbx/kv_mdbx.go +++ b/kv/mdbx/kv_mdbx.go @@ -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)