mirror of https://github.com/status-im/consul.git
consul: Add a guard against deadlock in MDB
This commit is contained in:
parent
3897a23db2
commit
e29b9ca50a
|
@ -7,6 +7,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -181,6 +182,12 @@ func (t *MDBTable) StartTxn(readonly bool, mdbTxn *MDBTxn) (*MDBTxn, error) {
|
||||||
var tx *mdb.Txn
|
var tx *mdb.Txn
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
// Panic if we deadlock acquiring a transaction
|
||||||
|
timeout := time.AfterFunc(5*time.Second, func() {
|
||||||
|
panic("Timeout starting MDB transaction, potential deadlock")
|
||||||
|
})
|
||||||
|
defer timeout.Stop()
|
||||||
|
|
||||||
// Ensure the modes agree
|
// Ensure the modes agree
|
||||||
if mdbTxn != nil {
|
if mdbTxn != nil {
|
||||||
if mdbTxn.readonly != readonly {
|
if mdbTxn.readonly != readonly {
|
||||||
|
|
Loading…
Reference in New Issue