diff --git a/consul/mdb_table.go b/consul/mdb_table.go index f08dc9b809..0012f5e02e 100644 --- a/consul/mdb_table.go +++ b/consul/mdb_table.go @@ -7,6 +7,7 @@ import ( "reflect" "strings" "sync/atomic" + "time" ) var ( @@ -181,6 +182,12 @@ func (t *MDBTable) StartTxn(readonly bool, mdbTxn *MDBTxn) (*MDBTxn, error) { var tx *mdb.Txn 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 if mdbTxn != nil { if mdbTxn.readonly != readonly {