Skip to content

fix(consensus): release cs.mtx before sending to statsMsgQueue (backport #5813) - #5998

Merged
swift1337 merged 3 commits into
v0.38.xfrom
mergify/bp/v0.38.x/pr-5813
Jul 27, 2026
Merged

swift1337 merged 3 commits into
v0.38.xfrom
mergify/bp/v0.38.x/pr-5813

Conversation

@mergify

@mergify mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Problem

handleMsg sent to cs.statsMsgQueue while holding cs.mtx. If the buffer fills, the send blocks indefinitely — stalling the entire consensus state machine.

Fix

Hoist the statsMsgQueue send outside the switch, release cs.mtx before the send and re-acquire after.

This also removes the duplicated added checks inside each case block, replacing them with a single check at the bottom.

Testing

  • TestHandleMsgReleasesLockBeforeStatsMsgQueueSend: verifies GetRoundState() is not blocked while handleMsg is blocked on the send.

PR checklist

## Problem

`handleMsg` sent to `cs.statsMsgQueue` while holding `cs.mtx`. If the
buffer fills, the send blocks indefinitely — stalling the entire
consensus state machine.

## Fix

Hoist the `statsMsgQueue` send outside the `switch`, release `cs.mtx`
before the send and re-acquire after.

This also removes the duplicated `added` checks inside each `case`
block, replacing them with a single check at the bottom.

## Testing

- `TestHandleMsgReleasesLockBeforeStatsMsgQueueSend`: verifies
`GetRoundState()` is not blocked while `handleMsg` is blocked on the
send.

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dmitry S <[email protected]>
(cherry picked from commit bd8bb65)

# Conflicts:
#	CHANGELOG.md
@mergify mergify Bot added the conflicts label Jul 27, 2026
@mergify

mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of bd8bb65 has failed:

On branch mergify/bp/v0.38.x/pr-5813
Your branch is up to date with 'origin/v0.38.x'.

You are currently cherry-picking commit bd8bb655.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   consensus/state.go
	modified:   consensus/state_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   CHANGELOG.md

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@mergify

mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@swift1337
swift1337 merged commit 7cd4427 into v0.38.x Jul 27, 2026
13 of 17 checks passed
@swift1337
swift1337 deleted the mergify/bp/v0.38.x/pr-5813 branch July 27, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants