Skip to content

fix(streaming): bound NATS producer selection - #11287

Merged
ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:rb-fix-streaming-bound-nats-producer-index
Sep 17, 2026
Merged

ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:rb-fix-streaming-bound-nats-producer-index

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

NATS producer selection currently calls Math.Abs on the stream key's hash code. A hash of int.MinValue throws OverflowException, preventing the message from being published.

Route selection through an internal GetProducerIndex helper using unsigned modulo: (int)((uint)hashCode % (uint)producerCount). For positive producer counts, every hash maps to a valid producer index. This selects a publishing connection while the existing NATS subject determines stream partitioning.

The regression theory covers int.MinValue, -1, 0, and int.MaxValue with producer counts 1, 3, 8, and int.MaxValue, asserting exact indices and array bounds.

Extracted from #10798 into a standalone two-file fix based on current upstream main. The original commit, 210e0ba4ca94cd15b34691fb49bb80df945288ef, is preserved with cherry-pick -x and its author attribution to Reuben Bond.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 17, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Fixes NATS producer selection for int.MinValue hash codes using unsigned modulo arithmetic.

Changes:

  • Adds bounded producer-index calculation.
  • Routes publishing through the helper.
  • Adds boundary regression tests.
File Description
test/​Extensions/​Orleans.Streaming.NATS.Tests/​NatsOptionsTests.cs Covers hash and producer-count boundary cases.
src/​Orleans.Streaming.NATS/​Providers/​NatsConnectionManager.cs Uses safe unsigned-modulo producer selection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Sep 17, 2026
Move independent NATS producer selection and dimension validation to dotnet#11287 and dotnet#11293. Move standalone redaction, credential, and journaling regression coverage to dotnet#11288, dotnet#11289, dotnet#11291, and dotnet#11292; move the independent DynamoDB README recipes to dotnet#11292.

Retain Token redaction, credential binding and endpoint behavior, journaling activation, and NATS credential-safe logging as prerequisites until dotnet#11288, dotnet#11290, dotnet#11292, dotnet#11289, and dotnet#11291 are merged by humans. The original PR remains focused on Aspire configuration, resource ownership, and integration coverage.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Sep 17, 2026
Move independent NATS producer selection and dimension validation to dotnet#11287 and dotnet#11293. Move standalone redaction, credential, and journaling regression coverage to dotnet#11288, dotnet#11289, dotnet#11291, and dotnet#11292; move the independent DynamoDB README recipes to dotnet#11292.

Retain Token redaction, credential binding and endpoint behavior, journaling activation, and NATS credential-safe logging as prerequisites until dotnet#11288, dotnet#11290, dotnet#11292, dotnet#11289, and dotnet#11291 are merged by humans. The original PR remains focused on Aspire configuration, resource ownership, and integration coverage.
@github-actions

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 82.07% (112,026 / 136,506)
Branches 71.22% (32,204 / 45,219)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested 68f1f47, not current main 2e40fa8.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

@ReubenBond
ReubenBond merged commit 89931bb into dotnet:main Sep 17, 2026
73 checks passed
@ReubenBond
ReubenBond deleted the rb-fix-streaming-bound-nats-producer-index branch September 17, 2026 14:21
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Sep 17, 2026
Move independent NATS producer selection and dimension validation to dotnet#11287 and dotnet#11293. Move standalone redaction, credential, and journaling regression coverage to dotnet#11288, dotnet#11289, dotnet#11291, and dotnet#11292; move the independent DynamoDB README recipes to dotnet#11292.

Retain Token redaction, credential binding and endpoint behavior, journaling activation, and NATS credential-safe logging as prerequisites until dotnet#11288, dotnet#11290, dotnet#11292, dotnet#11289, and dotnet#11291 are merged by humans. The original PR remains focused on Aspire configuration, resource ownership, and integration coverage.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Sep 17, 2026
Move independent NATS producer selection and dimension validation to dotnet#11287 and dotnet#11293. Move standalone redaction, credential, and journaling regression coverage to dotnet#11288, dotnet#11289, dotnet#11291, and dotnet#11292; move the independent DynamoDB README recipes to dotnet#11292.

Retain Token redaction, credential binding and endpoint behavior, journaling activation, and NATS credential-safe logging as prerequisites until dotnet#11288, dotnet#11290, dotnet#11292, dotnet#11289, and dotnet#11291 are merged by humans. The original PR remains focused on Aspire configuration, resource ownership, and integration coverage.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Sep 17, 2026
Move independent NATS producer selection and dimension validation to dotnet#11287 and dotnet#11293. Move standalone redaction, credential, and journaling regression coverage to dotnet#11288, dotnet#11289, dotnet#11291, and dotnet#11292; move the independent DynamoDB README recipes to dotnet#11292.

Retain Token redaction, credential binding and endpoint behavior, journaling activation, and NATS credential-safe logging as prerequisites until dotnet#11288, dotnet#11290, dotnet#11292, dotnet#11289, and dotnet#11291 are merged by humans. The original PR remains focused on Aspire configuration, resource ownership, and integration coverage.
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