From 6ff765c63eb5420f739a1b36b0a4332120771e29 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Wed, 27 May 2020 18:59:38 +0200 Subject: [PATCH] catch and handle bootstrap join errors --- src/Hash2Pub/FediChord.hs | 1 + src/Hash2Pub/Main.hs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Hash2Pub/FediChord.hs b/src/Hash2Pub/FediChord.hs index 60d96ee..d159009 100644 --- a/src/Hash2Pub/FediChord.hs +++ b/src/Hash2Pub/FediChord.hs @@ -138,6 +138,7 @@ fediChordBootstrapJoin ns (joinHost, joinPort) = initCache bootstrapResponse fediChordJoin bootstrapCache ns ) + `catch` (\e -> pure . Left $ "Error at bootstrap joining: " <> displayException (e :: IOException)) -- | join a node to the DHT, using the provided cache snapshot for resolving the new -- node's position. diff --git a/src/Hash2Pub/Main.hs b/src/Hash2Pub/Main.hs index 4482012..fb58ad5 100644 --- a/src/Hash2Pub/Main.hs +++ b/src/Hash2Pub/Main.hs @@ -4,6 +4,7 @@ import Control.Concurrent import Control.Exception import Data.IP (IPv6, toHostAddress6) import System.Environment +import Data.Either import Hash2Pub.FediChord @@ -23,10 +24,21 @@ main = do tryJoining (bn:bns) = do j <- fediChordBootstrapJoin thisNode bn case j of - Left _ -> tryJoining bns + Left err -> putStrLn ("join error: " <> err) >> tryJoining bns Right joined -> pure $ Right joined tryJoining [] = pure $ Left "Exhausted all bootstrap points for joining." joinedState <- tryJoining $ confBootstrapNodes conf + either (\err -> + -- handle unsuccessful join + + putStrLn $ err <> " Error joining, start listening for incoming requests anyways" + -- TODO: periodic retry + ) + (\joinedNS -> + -- launch main eventloop with successfully joined state + putStrLn ("successful join at " <> (show . getNid $ joinedNS)) + ) + joinedState -- stop main thread from terminating during development getChar pure ()