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

[CDEC-470] Catch IOExceptions in productionReporter #3365

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

### Fixes

- #### Make productionReporter more robust
Add exception handling code in reporting exception handler, to prevent IOExceptions from killing
the main thread. This was noticed when the network connection was interrupted, and the reporter
died when it tried to report over the down network. (CDEC-470 / [PR 3365])

[PR 3365]: https://github.com/input-output-hk/cardano-sl/pull/3365

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

### Improvements

### Specifications
Expand Down
11 changes: 10 additions & 1 deletion lib/src/Pos/Reporting/Production.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ module Pos.Reporting.Production

import Universum

import Control.Exception.Safe (catchIO)

import Pos.Core (ProtocolMagic)
import Pos.Infra.Diffusion.Types (Diffusion)
import Pos.Infra.Reporting (Reporter (..))
import Pos.Infra.Reporting.Http (reportNode)
import Pos.Infra.Reporting.NodeInfo (extendWithNodeInfo)
import Pos.Infra.Reporting.Wlog (LoggerConfig, withWlogTempFile)
import Pos.Util.CompileInfo (CompileTimeInfo)
import Pos.Util.Trace (Severity, Trace)
import Pos.Util.Trace (Severity (Error), Trace, traceWith)

data ProductionReporterParams = ProductionReporterParams
{ prpServers :: ![Text]
Expand All @@ -32,9 +34,16 @@ productionReporter
productionReporter params diffusion = Reporter $ \rt -> withWlogTempFile logConfig $ \mfp -> do
rt' <- extendWithNodeInfo diffusion rt
reportNode logTrace protocolMagic compileTimeInfo servers mfp rt'
`catchIO`
reportExnHandler rt'
where
servers = prpServers params
logConfig = prpLoggerConfig params
protocolMagic = prpProtocolMagic params
compileTimeInfo = prpCompileTimeInfo params
logTrace = prpTrace params
--
reportExnHandler rt e =
let msgToLog = "reportNode encountered IOException `" <> show e
<> "` while trying to report the message:" <> show rt
in liftIO (traceWith logTrace (Error, msgToLog))