@@ -880,7 +880,6 @@ func (s *Switch) getLocalLink(pkt *htlcPacket, htlc *lnwire.UpdateAddHTLC) (
880
880
// Try to find links by node destination.
881
881
s .indexMtx .RLock ()
882
882
link , err := s .getLinkByShortID (pkt .outgoingChanID )
883
- defer s .indexMtx .RUnlock ()
884
883
if err != nil {
885
884
// If the link was not found for the outgoingChanID, an outside
886
885
// subsystem may be using the confirmed SCID of a zero-conf
@@ -892,6 +891,7 @@ func (s *Switch) getLocalLink(pkt *htlcPacket, htlc *lnwire.UpdateAddHTLC) (
892
891
// do that upon receiving the packet.
893
892
baseScid , ok := s .baseIndex [pkt .outgoingChanID ]
894
893
if ! ok {
894
+ s .indexMtx .RUnlock ()
895
895
log .Errorf ("Link %v not found" , pkt .outgoingChanID )
896
896
return nil , NewLinkError (& lnwire.FailUnknownNextPeer {})
897
897
}
@@ -900,10 +900,15 @@ func (s *Switch) getLocalLink(pkt *htlcPacket, htlc *lnwire.UpdateAddHTLC) (
900
900
// link.
901
901
link , err = s .getLinkByShortID (baseScid )
902
902
if err != nil {
903
+ s .indexMtx .RUnlock ()
903
904
log .Errorf ("Link %v not found" , baseScid )
904
905
return nil , NewLinkError (& lnwire.FailUnknownNextPeer {})
905
906
}
906
907
}
908
+ // We finished looking up the indexes, so we can unlock the mutex before
909
+ // performing the link operations which might also acquire the lock
910
+ // in case e.g. failAliasUpdate is called.
911
+ s .indexMtx .RUnlock ()
907
912
908
913
if ! link .EligibleToForward () {
909
914
log .Errorf ("Link %v is not available to forward" ,
@@ -928,6 +933,7 @@ func (s *Switch) getLocalLink(pkt *htlcPacket, htlc *lnwire.UpdateAddHTLC) (
928
933
"satisfied" , pkt .outgoingChanID )
929
934
return nil , htlcErr
930
935
}
936
+
931
937
return link , nil
932
938
}
933
939
0 commit comments