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

Commit 298773b

Browse files
authored
Merge pull request #3365 from input-output-hk/mhuesch/CDEC-470-develop
[CDEC-470] Catch IOExceptions in `productionReporter`
2 parents 15f2886 + 30f3621 commit 298773b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
### Fixes
99

10+
- #### Make productionReporter more robust
11+
Add exception handling code in reporting exception handler, to prevent IOExceptions from killing
12+
the main thread. This was noticed when the network connection was interrupted, and the reporter
13+
died when it tried to report over the down network. (CDEC-470 / [PR 3365])
14+
15+
[PR 3365]: https://github.com/input-output-hk/cardano-sl/pull/3365
16+
1017
### Improvements
1118

1219
### Specifications

lib/src/Pos/Reporting/Production.hs

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ module Pos.Reporting.Production
88

99
import Universum
1010

11+
import Control.Exception.Safe (catchIO)
12+
1113
import Pos.Core (ProtocolMagic)
1214
import Pos.Infra.Diffusion.Types (Diffusion)
1315
import Pos.Infra.Reporting (Reporter (..))
1416
import Pos.Infra.Reporting.Http (reportNode)
1517
import Pos.Infra.Reporting.NodeInfo (extendWithNodeInfo)
1618
import Pos.Infra.Reporting.Wlog (LoggerConfig, withWlogTempFile)
1719
import Pos.Util.CompileInfo (CompileTimeInfo)
18-
import Pos.Util.Trace (Severity, Trace)
20+
import Pos.Util.Trace (Severity (Error), Trace, traceWith)
1921

2022
data ProductionReporterParams = ProductionReporterParams
2123
{ prpServers :: ![Text]
@@ -32,9 +34,16 @@ productionReporter
3234
productionReporter params diffusion = Reporter $ \rt -> withWlogTempFile logConfig $ \mfp -> do
3335
rt' <- extendWithNodeInfo diffusion rt
3436
reportNode logTrace protocolMagic compileTimeInfo servers mfp rt'
37+
`catchIO`
38+
reportExnHandler rt'
3539
where
3640
servers = prpServers params
3741
logConfig = prpLoggerConfig params
3842
protocolMagic = prpProtocolMagic params
3943
compileTimeInfo = prpCompileTimeInfo params
4044
logTrace = prpTrace params
45+
--
46+
reportExnHandler rt e =
47+
let msgToLog = "reportNode encountered IOException `" <> show e
48+
<> "` while trying to report the message:" <> show rt
49+
in liftIO (traceWith logTrace (Error, msgToLog))

0 commit comments

Comments
 (0)