Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 76e0019

Browse files
committed
[CDEC-469] Catch reporter IOExceptions in retrievalWorker
1 parent db68e2f commit 76e0019

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

block/src/Pos/Block/Network/Retrieval.hs

+13-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import Universum
1010

1111
import Control.Concurrent.STM (putTMVar, swapTMVar, tryReadTBQueue, tryReadTMVar,
1212
tryTakeTMVar, readTBQueue, TBQueue)
13-
import Control.Exception.Safe (handleAny)
13+
import Control.Exception (IOException)
14+
import Control.Exception.Safe (catch, handleAny)
1415
import Control.Lens (to)
1516
import Control.Monad.STM (retry)
1617
import qualified Data.List.NonEmpty as NE
1718
import Data.Time.Units (Second)
18-
import Formatting (build, int, sformat, (%))
19+
import Formatting (build, int, sformat, shown, (%))
1920
import Mockable (delay)
2021
import qualified System.Metrics.Gauge as Gauge
2122
import System.Wlog (logDebug, logError, logInfo, logWarning)
@@ -26,7 +27,8 @@ import Pos.Block.Network.Logic (BlockNetLogicException (..), handleBlo
2627
triggerRecovery)
2728
import Pos.Block.RetrievalQueue (BlockRetrievalQueueTag, BlockRetrievalTask (..))
2829
import Pos.Block.Types (RecoveryHeaderTag)
29-
import Pos.Core (Block, HasHeaderHash (..), HeaderHash, difficultyL, isMoreDifficult)
30+
import Pos.Core (Block, HasHeaderHash (..), HeaderHash, difficultyL, headerHashF,
31+
isMoreDifficult)
3032
import Pos.Core.Block (BlockHeader)
3133
import Pos.Core.Chrono (NE, OldestFirst (..), _OldestFirst)
3234
import Pos.Crypto (ProtocolMagic, shortHashF)
@@ -147,10 +149,15 @@ retrievalWorker pm diffusion = do
147149
-- again.
148150
handleRecoveryE nodeId rHeader e = do
149151
-- REPORT:ERROR 'reportOrLogW' in block retrieval worker/recovery.
150-
reportOrLogW (sformat
151-
("handleRecoveryE: error handling nodeId="%build%", header="%build%": ")
152-
nodeId (headerHash rHeader)) e
152+
reportOrLogW (sformat errfmt nodeId (headerHash rHeader)) e
153+
`catch` handleIOException
153154
dropRecoveryHeaderAndRepeat pm diffusion nodeId
155+
where
156+
errfmt = "handleRecoveryE: error handling nodeId="%build%", header="%headerHashF%": "
157+
158+
handleIOException :: IOException -> m ()
159+
handleIOException _ = logError $ sformat (errfmt%shown) nodeId (headerHash rHeader) e
160+
154161

155162
-- Recovery handling. We assume that header in the recovery variable is
156163
-- appropriate and just query headers/blocks.

0 commit comments

Comments
 (0)