htlcswitch: ensure we don't attempt to create fwding events for fails

In this commit, we fix an existing source of a panic, that could at
times lead to a deadlock. If the circuit returned from closeCircuit
didn't have an outgoing key (as it was an incomplete forward), then we
would attempt to de-ref a nil pointer. This would trigger a panic, and
the runtime would start to unwind the stack, and execute each defer in
line. A deadlock can arise here, as in the defer at the root goroutine,
we need to grab the fwdingEventMtx. However, we already have it at the
panic site.

We fix this issue by ensuring we only attempt to add the event if it's a
_settle_ and also actually has an outgoing circuit (which it should
already, just a defensive check).
This commit is contained in:
Olaoluwa Osuntokun 2018-05-22 16:46:55 -07:00
parent 95293f5102
commit 5e3b239ebc
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -1061,7 +1061,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
fail.Reason,
)
}
} else {
} else if !isFail && circuit.Outgoing != nil {
// If this is an HTLC settle, and it wasn't from a
// locally initiated HTLC, then we'll log a forwarding
// event so we can flush it to disk later.