Skip to content

Commit 9498447

Browse files
authored
fix: proactively check for shutdown event (#1396)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> The log lines in the execute method were panicing due to un-caught shutdown events. This nicely handles that. This was verified locally. Previously the test would panic when run in a loop < 10 times. Now you can run it 100x 👍 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Implemented a check to prevent block execution during node shutdown, enhancing system stability. - Updated the execution process to utilize the provided context for better operation tracking and cancellation support. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 24c09a0 commit 9498447

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

state/executor.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ func (e *BlockExecutor) Validate(state types.State, block *types.Block) error {
327327
}
328328

329329
func (e *BlockExecutor) execute(ctx context.Context, state types.State, block *types.Block) (*abci.ResponseFinalizeBlock, error) {
330+
// Only execute if the node hasn't already shut down
331+
select {
332+
case <-ctx.Done():
333+
return nil, ctx.Err()
334+
default:
335+
}
330336
abciHeader, err := abciconv.ToABCIHeaderPB(&block.SignedHeader.Header)
331337
if err != nil {
332338
return nil, err
@@ -337,7 +343,7 @@ func (e *BlockExecutor) execute(ctx context.Context, state types.State, block *t
337343
return nil, err
338344
}
339345

340-
finalizeBlockResponse, err := e.proxyApp.FinalizeBlock(context.TODO(), &abci.RequestFinalizeBlock{
346+
finalizeBlockResponse, err := e.proxyApp.FinalizeBlock(ctx, &abci.RequestFinalizeBlock{
341347
Hash: block.Hash(),
342348
NextValidatorsHash: nil,
343349
ProposerAddress: abciHeader.ProposerAddress,

0 commit comments

Comments
 (0)