From 5f7494fbf652e2ad3ecddc7d7d49780d0c73a8a0 Mon Sep 17 00:00:00 2001 From: Hans Moog <hm@mkjc.net> Date: Tue, 30 Jul 2019 16:54:11 +0200 Subject: [PATCH] Fix: fixed shutdown error due to autopeering --- .../protocol/outgoing_request_processor.go | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/plugins/autopeering/protocol/outgoing_request_processor.go b/plugins/autopeering/protocol/outgoing_request_processor.go index 88b95669..ea2f3745 100644 --- a/plugins/autopeering/protocol/outgoing_request_processor.go +++ b/plugins/autopeering/protocol/outgoing_request_processor.go @@ -1,6 +1,9 @@ package protocol import ( + "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" + "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" + "github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp" "time" "github.com/iotaledger/goshimmer/packages/timeutil" @@ -10,10 +13,7 @@ import ( "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" - "github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" ) @@ -46,14 +46,27 @@ func sendOutgoingRequests(plugin *node.Plugin) { timeutil.Sleep(5 * time.Second) if candidateShouldBeContacted(chosenNeighborCandidate) { - if dialed, err := chosenNeighborCandidate.Send(outgoingrequest.INSTANCE.Marshal(), types.PROTOCOL_TYPE_TCP, true); err != nil { - plugin.LogDebug(err.Error()) - } else { - plugin.LogDebug("sent peering request to " + chosenNeighborCandidate.String()) + doneChan := make(chan int, 1) + + go func(doneChan chan int) { + if dialed, err := chosenNeighborCandidate.Send(outgoingrequest.INSTANCE.Marshal(), types.PROTOCOL_TYPE_TCP, true); err != nil { + plugin.LogDebug(err.Error()) + } else { + plugin.LogDebug("sent peering request to " + chosenNeighborCandidate.String()) - if dialed { - tcp.HandleConnection(chosenNeighborCandidate.Conn) + if dialed { + tcp.HandleConnection(chosenNeighborCandidate.Conn) + } } + + close(doneChan) + }(doneChan) + + select { + case <-daemon.ShutdownSignal: + return + case <-doneChan: + continue } } } -- GitLab