Skip to content

Commit

Permalink
Have the node continue running even if client closes its socket
Browse files Browse the repository at this point in the history
  • Loading branch information
koslambrou committed Sep 29, 2023
1 parent 78d699c commit 368cfb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cardano-node/src/Cardano/Node/LedgerEvent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 368cfb1

Please sign in to comment.