diff --git a/CHANGELOG.md b/CHANGELOG.md index bf1df7b1966..4e0d115d621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + ### Improvements ### Specifications diff --git a/lib/src/Pos/Reporting/Production.hs b/lib/src/Pos/Reporting/Production.hs index 5ba1970890b..e5ea3e93713 100644 --- a/lib/src/Pos/Reporting/Production.hs +++ b/lib/src/Pos/Reporting/Production.hs @@ -8,6 +8,8 @@ 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 (..)) @@ -15,7 +17,7 @@ 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] @@ -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))