Skip to content

runtime: wake select receivers for unbuffered sends#1691

Open
cpunion wants to merge 4 commits intogoplus:mainfrom
cpunion:fix/issue-694-select-unbuffered-wakeup
Open

runtime: wake select receivers for unbuffered sends#1691
cpunion wants to merge 4 commits intogoplus:mainfrom
cpunion:fix/issue-694-select-unbuffered-wakeup

Conversation

@cpunion
Copy link
Collaborator

@cpunion cpunion commented Mar 9, 2026

Fixes #694.

Summary

  • add a regression test for a goroutine blocked in select on an unbuffered receive while another goroutine starts a blocking send
  • wake registered select receivers when an unbuffered sender transitions into the blocked-send state

Validation

  • go test ./test -run TestSelectRecvWakesForBlockedUnbufferedSend -count=1
  • /tmp/llgo-694 test ./test -run TestSelectRecvWakesForBlockedUnbufferedSend -count=1
  • /tmp/llgo-694 run ./cl/_testgo/select
  • /tmp/llgo-694 run ./cl/_testgo/selects
  • repeated issue repro binary execution: 200/200 pass
  • go test ./test -count=1
  • /tmp/llgo-694 test ./test -count=1

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a concurrency issue where select-based receivers might not be woken up when an unbuffered channel sender becomes blocked. The fix involves explicitly notifying select operations (notifyOps) when an unbuffered send enters a blocked state, ensuring that waiting receivers can correctly process the pending send. A new regression test has been added to prevent future regressions of this specific scenario.

Highlights

  • Unbuffered Send Wake-up: Implemented a mechanism to wake registered select receivers when an unbuffered sender transitions into a blocked state, ensuring proper channel communication.
  • Regression Test: Introduced a new regression test (TestSelectRecvWakesForBlockedUnbufferedSend) to validate that goroutines blocked in select on an unbuffered receive are correctly woken by a blocking send.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • runtime/internal/runtime/z_chan.go
    • Added a call to notifyOps within the ChanSend function when an unbuffered channel's send operation blocks, ensuring select receivers are notified.
  • test/select_test.go
    • Created TestSelectRecvWakesForBlockedUnbufferedSend to verify that a select receiver is correctly woken when an unbuffered send blocks.
Activity
  • A regression test was added to cover the specific scenario of a goroutine blocked in select on an unbuffered receive while another goroutine starts a blocking send.
  • The core fix involves waking registered select receivers when an unbuffered sender transitions into the blocked-send state.
  • Validation steps were performed using go test and a custom llgo tool, including repeated execution of the issue reproduction binary, all passing successfully.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@xgopilot
Copy link
Contributor

xgopilot bot commented Mar 9, 2026

Clean, well-targeted fix for a real race condition. The placement of notifyOps(p) after p.sends++ and before p.cond.Wait() correctly ensures select-based receivers are woken when a sender becomes available. The test is a good regression test. Left a couple of minor inline comments.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue where select receivers were not being woken up for unbuffered sends. The fix in runtime/internal/runtime/z_chan.go correctly notifies select operations when an unbuffered sender is about to block, which seems appropriate. The new regression test in test/select_test.go effectively covers the scenario. I've identified a minor issue in the test where a goroutine could leak in case of a timeout and have provided a suggestion to make the test more robust.

Note: Security Review did not run due to the size of the PR.

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (eda01de) to head (194199a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1691   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          48       48           
  Lines       13314    13314           
=======================================
  Hits        12404    12404           
  Misses        724      724           
  Partials      186      186           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Unexpected channel behavior

1 participant