consul: Add a guard against deadlock in MDB

This commit is contained in:
Armon Dadgar 2014-02-04 19:04:36 -08:00
parent 3897a23db2
commit e29b9ca50a
1 changed files with 7 additions and 0 deletions

View File

@ -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 {