From dc6abf7498e9b5d0c5930747dc46a9862313f3d0 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Thu, 29 Jul 2021 19:03:41 +0530 Subject: [PATCH] cleanup channel in a go-routine --- channels/channels_fsm.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/channels/channels_fsm.go b/channels/channels_fsm.go index 02768eee..6b7ad6f4 100644 --- a/channels/channels_fsm.go +++ b/channels/channels_fsm.go @@ -222,9 +222,16 @@ func cleanupConnection(ctx fsm.Context, env ChannelEnvironment, channel internal if otherParty == env.ID() { otherParty = channel.Responder } - env.CleanupChannel(datatransfer.ChannelID{ID: channel.TransferID, Initiator: channel.Initiator, Responder: channel.Responder}) - env.Unprotect(otherParty, datatransfer.ChannelID{ID: channel.TransferID, Initiator: channel.Initiator, Responder: channel.Responder}.String()) - return ctx.Trigger(datatransfer.CleanupComplete) + + + // the state machine event loop will block on these calls if we don't spin up a go-routine here. + go func() { + env.CleanupChannel(datatransfer.ChannelID{ID: channel.TransferID, Initiator: channel.Initiator, Responder: channel.Responder}) + env.Unprotect(otherParty, datatransfer.ChannelID{ID: channel.TransferID, Initiator: channel.Initiator, Responder: channel.Responder}.String()) + _ = ctx.Trigger(datatransfer.CleanupComplete) + }() + + return nil } // CleanupStates are the penultimate states for a channel