From 6219b934300b652bb26a4d490c5c3cb95d9bf7c0 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Mon, 25 May 2020 14:30:43 +0300 Subject: [PATCH 1/2] [NOD-1018] Exit after 2 minutes if graceful shutdown fails (#732) * [NOD-1018] Exit after 2 minutes if graceful shutdown fails * [NOD-1018] Change time.Tick to time.After --- kaspad.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kaspad.go b/kaspad.go index 7b3db8260..7293f0036 100644 --- a/kaspad.go +++ b/kaspad.go @@ -13,6 +13,7 @@ import ( "runtime/debug" "runtime/pprof" "strings" + "time" "github.com/kaspanet/kaspad/dbaccess" @@ -145,7 +146,20 @@ func kaspadMain(serverChan chan<- *server.Server) error { defer func() { kasdLog.Infof("Gracefully shutting down the server...") server.Stop() - server.WaitForShutdown() + + shutdownDone := make(chan struct{}) + go func() { + server.WaitForShutdown() + shutdownDone <- struct{}{} + }() + + const shutdownTimeout = 2 * time.Minute + + select { + case <-shutdownDone: + case <-time.After(shutdownTimeout): + kasdLog.Criticalf("Graceful shutdown timed out %s. Terminating...", shutdownTimeout) + } srvrLog.Infof("Server shutdown complete") }() server.Start() From d15c009b3c4ab434ebb98587b6c69bbb6cea6b82 Mon Sep 17 00:00:00 2001 From: stasatdaglabs <39559713+stasatdaglabs@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:11:05 +0300 Subject: [PATCH 2/2] [NOD-1030] Disconnect from syncPeers that send orphan blocks (#744) * [NOD-1030] Disconnect from syncPeers that send orphan blocks. * [NOD-1030] Remove debug log. * [NOD-1030] Remove unnecessary call to stopSyncFromPeer. --- netsync/manager.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/netsync/manager.go b/netsync/manager.go index fc43d7fbe..31923cc62 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -529,8 +529,17 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) { return } - // Request the parents for the orphan block from the peer that sent it. if isOrphan { + // If we received an orphan block from the sync peer, it is + // misbehaving and must be disconnected from. + if peer == sm.syncPeer { + log.Errorf("Received an orphan block %s from sync peer %s. Disconnecting...", + blockHash, peer) + peer.Disconnect() + return + } + + // Request the parents for the orphan block from the peer that sent it. missingAncestors, err := sm.dag.GetOrphanMissingAncestorHashes(blockHash) if err != nil { log.Errorf("Failed to find missing ancestors for block %s: %s",