fabric icon indicating copy to clipboard operation
fabric copied to clipboard

Fix panic on peer shutdown during block commit

Open Ady0333 opened this issue 9 months ago • 6 comments

Type of change

  • Bug fix

Description

This PR fixes a shutdown race in GossipStateProviderImpl that could cause a peer to panic during block commit.

On shutdown, Stop() closed the ledger immediately after signaling stopCh, while the deliverPayloads() goroutine could still be committing blocks. That commit path sends events to the snapshot manager, whose channels are closed as part of ledger.Close(). If shutdown overlaps with an in-flight commit, this results in a send on closed channel panic.

The fix waits for deliverPayloads() to complete before closing ledger resources and adds a stop check in the payload loop so shutdown exits promptly.


Additional details

The shutdown path is now coordinated with block commit to ensure no snapshot manager channels are closed while still in use.

Tested locally with go test ./gossip/state/....


Release Note

Fixes a peer shutdown race that could cause a panic during block commit when snapshot manager channels were closed while still in use.

Ady0333 avatar Feb 09 '26 20:02 Ady0333

Hi @yacovm ,

When you get a chance, please take a look at this PR.

Ady0333 avatar Feb 09 '26 20:02 Ady0333

@Ady0333 can you please add unit test?

C0rWin avatar Feb 20 '26 22:02 C0rWin

Thank you for the contribution. We currently have neither a peer node stop nor a peer node shutdown command. Because of this, I’m not sure what this PR is intended to address. Our existing shutdown APIs are only used within tests to close services after a unit test run.

cendhu avatar Mar 09 '26 04:03 cendhu

@cendhu Thanks for the clarification.

My understanding was that snapshotMgr.shutdown() can close channels while snapshot generation goroutines are still active, which could lead to a send-on-closed-channel panic. Even if shutdown is currently only used in tests, this panic could still cause non-deterministic failures in test environments where snapshots are generated concurrently.

The intent of the fix was to prevent this race and ensure shutdown happens safely even when snapshot generation is in progress.

Please let me know if this scenario is not considered relevant for Fabric, and I can close the PR if needed.

Ady0333 avatar Mar 11 '26 05:03 Ady0333

@cendhu Thanks for the clarification.

My understanding was that snapshotMgr.shutdown() can close channels while snapshot generation goroutines are still active, which could lead to a send-on-closed-channel panic. Even if shutdown is currently only used in tests, this panic could still cause non-deterministic failures in test environments where snapshots are generated concurrently.

The intent of the fix was to prevent this race and ensure shutdown happens safely even when snapshot generation is in progress.

Please let me know if this scenario is not considered relevant for Fabric, and I can close the PR if needed.

I agree with @cendhu . We need clear evidence of the importance of your correction, for example, in the form of an integration test, so that the test ends in panic without your correction.

pfi79 avatar Mar 21 '26 15:03 pfi79

@pfi79 Thankyou for keeping your view on this.

I agree with your point and I will add an integration test for this fix shortly.

Ady0333 avatar Mar 22 '26 05:03 Ady0333