Skip to content

Recover from panic in HandleTransaction to prevent peer crash (backport #5472)#5473

Merged
pfi79 merged 1 commit into
release-2.5from
mergify/bp/release-2.5/pr-5472
May 7, 2026
Merged

Recover from panic in HandleTransaction to prevent peer crash (backport #5472)#5473
pfi79 merged 1 commit into
release-2.5from
mergify/bp/release-2.5/pr-5472

Conversation

@mergify

@mergify mergify Bot commented May 7, 2026

Copy link
Copy Markdown

Summary

When a transaction times out during a range query, the timeout path in Execute() closes LevelDB iterators via CloseQueryIterators() while the handler goroutine (spawned by handleMessageReadyState) is still actively calling iter.Next(). This causes a nil pointer dereference in the LevelDB iterator that crashes the peer process.

Changes

  • Added a deferred recover() in HandleTransaction (core/chaincode/handler.go) to catch panics from concurrent iterator access and return an error response instead of crashing the peer
  • Added regression tests that verify the panic is recovered and an error response is sent, and that the transaction ID is properly deregistered

Testing

All 320 existing tests pass, including the 2 new regression tests:


This is an automatic backport of pull request #5472 done by [Mergify](https://mergify.com).

When a transaction times out during a range query, the timeout path
closes LevelDB iterators while the handler goroutine is still using
them, causing a nil pointer dereference that crashes the peer.

Add a deferred recover() in HandleTransaction to catch such panics
and return an error response instead of crashing. This is safe because
the transaction has already timed out and the resources are being freed.

The panic value is logged but not included in the response payload to
avoid violating endorsement determinism across peers. Metrics are
recorded in the recover path to match the normal code path.

Also adds regression tests that verify the panic is recovered and
an error response is sent.

Fixes #5048

Signed-off-by: Jaskirat-s7 <jaskiratsingh7812@gmail.com>
(cherry picked from commit 6a67397)
@mergify mergify Bot requested a review from a team as a code owner May 7, 2026 07:24
@pfi79 pfi79 merged commit c748fd8 into release-2.5 May 7, 2026
75 of 81 checks passed
@pfi79 pfi79 deleted the mergify/bp/release-2.5/pr-5472 branch May 7, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants