diff --git a/cardano-node/src/Cardano/Node/LedgerEvent.hs b/cardano-node/src/Cardano/Node/LedgerEvent.hs index 024aa703486..7b58dd661e1 100644 --- a/cardano-node/src/Cardano/Node/LedgerEvent.hs +++ b/cardano-node/src/Cardano/Node/LedgerEvent.hs @@ -112,6 +112,7 @@ import Cardano.Ledger.Conway.Rules (ConwayNewEpochEvent, ConwayEpochEvent) import qualified Cardano.Ledger.Conway.Rules as Conway import qualified Cardano.Ledger.Shelley.API as ShelleyAPI import Cardano.Ledger.Alonzo.Rules (AlonzoBbodyEvent (ShelleyInAlonzoEvent), AlonzoUtxowEvent (WrappedShelleyEraEvent), AlonzoUtxoEvent (UtxosEvent), AlonzoUtxosEvent) +import GHC.IO.Exception (IOException(IOError, ioe_type), IOErrorType (ResourceVanished)) type LedgerState crypto = ExtLedgerState (HardForkBlock (CardanoEras crypto)) @@ -812,4 +813,10 @@ withLedgerEventsServerStream port handler = do Nothing -> pure () Just e -> do let anchoredEvent = AnchoredEvent (getOneEraHash headerHash) slotNo e - BS.hPut h $ serializeAnchoredEvent (eventCodecVersion event) anchoredEvent + catch (BS.hPut h $ serializeAnchoredEvent (eventCodecVersion event) anchoredEvent) $ \case + -- If the client closes the socket, we continue running the node, but ignore the events. + IOError { ioe_type = ResourceVanished } -> do + pure () + err -> do + print err + throwIO err diff --git a/cardano-node/src/Cardano/Node/Run.hs b/cardano-node/src/Cardano/Node/Run.hs index 03423369850..1a0a2a97d19 100644 --- a/cardano-node/src/Cardano/Node/Run.hs +++ b/cardano-node/src/Cardano/Node/Run.hs @@ -179,7 +179,7 @@ runNode cmdPc = do handleNodeWithTracers ledgerEventHandler cmdPc nc p networkMagic runP - (SomeConsensusProtocol _ runP, _) -> + (SomeConsensusProtocol _ runP, _noGivenPort) -> handleNodeWithTracers discardEvent cmdPc nc p networkMagic runP