Skip to content

Harden channel select concurrency#9

Merged
loreste merged 1 commit into
loreste:mainfrom
attahn:test/seeded-channel-select-stress
Jul 20, 2026
Merged

Harden channel select concurrency#9
loreste merged 1 commit into
loreste:mainfrom
attahn:test/seeded-channel-select-stress

Conversation

@attahn

@attahn attahn commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Concurrent channel selectors shared result and round-robin state, allowing tasks to race and read another selector's value.

  • Initialize the shared select wakeup exactly once.
  • Keep integer, string, and pointer-backed select state thread-local.
  • Add replayable channel/select stress coverage under TSan.

Verified with cargo test --bin mako and the fixed TSan stress seeds.

Summary by CodeRabbit

  • Bug Fixes

    • Improved concurrent channel selection to isolate selector state across threads and prevent data races.
    • Improved select wakeup initialization for reliable multithreaded operation.
  • Tests

    • Added deterministic, seed-controlled stress coverage for channel selection, timeouts, closures, and typed selectors.
    • Added ThreadSanitizer replay scenarios using configurable seeds and rounds.
  • Documentation

    • Updated concurrency, soundness, roadmap, status, and CLI documentation with stress-test coverage and replay instructions.

@attahn

attahn commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai[bot] review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 72f77619-4ea4-4042-b616-d8018e45dea5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The runtime now stores channel-select values and round-robin cursors per thread, initializes shared wakeup synchronization once, and adds deterministic integer, string, and struct channel-select stress coverage with fixed-seed TSan replay documentation.

Changes

Channel select stress

Layer / File(s) Summary
Thread-local select state and wakeup initialization
runtime/mako_rt.h
Select values and round-robin cursors use TLS, while shared wakeup synchronization uses platform-specific one-time initialization.
Seeded integer channel stress scenarios
examples/testing/chan_select_stress_test.mko
Deterministic producers and seeded rounds cover fan-in, close behavior, concurrent selectors, uniqueness, and runtime statistics.
Concurrent typed selectors and timeout cleanup
examples/testing/chan_select_stress_test.mko
String and struct selectors run concurrently, and the timeout/default test closes its channel after validation.
TSan replay and soundness records
.github/workflows/ci.yml, docs/BUILTINS.md, docs/ROADMAP.md, docs/SOUNDNESS.md, docs/STATUS.md, CHANGELOG.md
CI and documentation record fixed-seed replay commands, seeded stress coverage, and updated RT-005 status text.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StressTest
  participant Producers
  participant Selectors
  participant Channels
  StressTest->>Producers: start deterministic seeded producers
  Producers->>Channels: send values and close selected channels
  Selectors->>Channels: perform timed select receives
  Channels-->>StressTest: return received values for uniqueness and statistics checks
Loading

Suggested reviewers: loreste

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: hardening concurrent channel select behavior and stress coverage.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@attahn
attahn marked this pull request as ready for review July 20, 2026 18:40
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

@attahn I’ll review the changes in #9, with particular attention to select-state isolation, one-time wakeup initialization, and concurrency-test coverage.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@attahn

attahn commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@loreste
loreste merged commit 2a1a853 into loreste:main Jul 20, 2026
12 checks passed
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