From 89751f869f0b819cc99a79692ce6ddd6da3157e7 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 17 Mar 2021 12:00:14 +0100 Subject: [PATCH 1/2] routing: fix mission control deadlock This commit fixes the following potential deadlock situation: * Pathfinding holds a database lock and tries to obtain a mission control lock via GetProbability * ReportPaymentSuccess/ReportPaymentFail holds a mission control lock and tries to obtain a database lock to store the payment result. --- routing/missioncontrol.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index 29d62dcc..2118c1b8 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -371,9 +371,6 @@ func (m *MissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route, failureSourceIdx *int, failure lnwire.FailureMessage) ( *channeldb.FailureReason, error) { - m.Lock() - defer m.Unlock() - timestamp := m.now() result := &paymentResult{ @@ -394,9 +391,6 @@ func (m *MissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route, func (m *MissionControl) ReportPaymentSuccess(paymentID uint64, rt *route.Route) error { - m.Lock() - defer m.Unlock() - timestamp := m.now() result := &paymentResult{ @@ -421,6 +415,9 @@ func (m *MissionControl) processPaymentResult(result *paymentResult) ( return nil, err } + m.Lock() + defer m.Unlock() + // Apply result to update mission control state. reason := m.applyPaymentResult(result) From 56238ebc609998dcf503dc4d0f14a7a064d2a24d Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 17 Mar 2021 12:06:12 +0100 Subject: [PATCH 2/2] routing: remove unnecessary lock in mission control init The init code is part of the instantiation, so there is no need for locking yet. --- routing/missioncontrol.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index 2118c1b8..57ed666d 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -238,9 +238,6 @@ func NewMissionControl(db kvdb.Backend, self route.Vertex, func (m *MissionControl) init() error { log.Debugf("Mission control state reconstruction started") - m.Lock() - defer m.Unlock() - start := time.Now() results, err := m.store.fetchAll()