Browse Source

consul: Add a guard against deadlock in MDB

pull/19/head
Armon Dadgar 11 years ago
parent
commit
e29b9ca50a
  1. 7
      consul/mdb_table.go

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

Loading…
Cancel
Save