Skip to content

fix: use buffered channel to prevent deadlock in state machine#2215

Merged
nimrod-teich merged 2 commits into
mainfrom
fix/unbuffered-channel-deadlock-risk
Feb 15, 2026
Merged

fix: use buffered channel to prevent deadlock in state machine#2215
nimrod-teich merged 2 commits into
mainfrom
fix/unbuffered-channel-deadlock-risk

Conversation

@nimrod-teich

Copy link
Copy Markdown
Contributor

The relayTaskChannel was created as an unbuffered channel, which could cause a deadlock when the receiving goroutine exits prematurely (e.g., due to context cancellation or errors). In this scenario, sends to the channel would block indefinitely since there's no receiver.

This fix adds a buffer of 1 to the channel, allowing the sender to proceed even if the receiver has exited, preventing potential deadlocks.

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • read the contribution guide
  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the main branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@codecov

codecov Bot commented Feb 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
consensus 8.55% <ø> (ø)
protocol 34.11% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...otocol/rpcconsumer/consumer_relay_state_machine.go 77.56% <100.00%> (ø)
.../rpcsmartrouter/smartrouter_relay_state_machine.go 81.25% <100.00%> (+0.41%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nimrod-teich nimrod-teich force-pushed the fix/unbuffered-channel-deadlock-risk branch from 75aa056 to cc1baed Compare February 1, 2026 15:19
@github-actions

github-actions Bot commented Feb 1, 2026

Copy link
Copy Markdown

Test Results

    7 files  ±0     85 suites  ±0   31m 49s ⏱️ +48s
3 345 tests +8  3 344 ✅ +8  1 💤 ±0  0 ❌ ±0 
3 538 runs  +8  3 537 ✅ +8  1 💤 ±0  0 ❌ ±0 

Results for commit cc1baed. ± Comparison against base commit 4479425.

NadavLevi
NadavLevi previously approved these changes Feb 15, 2026
The relayTaskChannel was created as an unbuffered channel, which could
cause a deadlock when the receiving goroutine exits prematurely (e.g.,
due to context cancellation or errors). In this scenario, sends to the
channel would block indefinitely since there's no receiver.

This fix adds a buffer of 1 to the channel, allowing the sender to
proceed even if the receiver has exited, preventing potential deadlocks.
The relayTaskChannel was created as an unbuffered channel in both
SmartRouterRelayStateMachine and ConsumerRelayStateMachine, which
could cause a deadlock when the receiving goroutine exits prematurely
(e.g., due to context cancellation or errors). In this scenario, sends
to the channel would block indefinitely since there's no receiver.

This fix adds a buffer of 1 to the channel, allowing the sender to
proceed even if the receiver has exited, preventing potential deadlocks.

Files changed:
- protocol/rpcsmartrouter/smartrouter_relay_state_machine.go
- protocol/rpcconsumer/consumer_relay_state_machine.go
- protocol/rpcsmartrouter/smartrouter_relay_state_machine_test.go (tests)
- protocol/rpcconsumer/consumer_relay_state_machine_test.go (tests)
@nimrod-teich nimrod-teich force-pushed the fix/unbuffered-channel-deadlock-risk branch from cc1baed to dcbc111 Compare February 15, 2026 13:06
@nimrod-teich nimrod-teich merged commit 0ba610d into main Feb 15, 2026
15 checks passed
@nimrod-teich nimrod-teich deleted the fix/unbuffered-channel-deadlock-risk branch February 15, 2026 13:06
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