GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(streaming): don't recycle in-flight pooled buffers mid-batch by ReubenBond · Pull Request #10264 · dotnet/orleans

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Jul 15, 2026 •
edited by dotnet-policy-service Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Problem

Fixes #10263.

Pooled stream caches (EventHub, Memory, Generator) can silently corrupt message payloads, which later surfaces as an ArgumentOutOfRangeException in SegmentBuilder.ReadNextString.

ChronologicalEvictionStrategy.OnBlockAllocated eagerly freed the previous pooled buffer whenever the cache reported empty (PurgeObservable.IsEmpty). That was safe when the strategy was written, but callers now encode an entire batch into pooled buffers before committing it to the cache. During that encode IsEmpty stays true, so the buffer being freed can still hold in-flight, uncommitted segments for the current batch. The freed buffer is returned to the (LIFO) object pool, and the very next allocation in the same batch pops it straight back and overwrites the earlier segments from offset 0 — corrupting those messages. The three pooled caches all share this eviction strategy, so all of them are affected, not just EventHub.

Solution

Remove the eager-free branch in OnBlockAllocated. In-use buffers are already reclaimed correctly at purge time by FreePurgedBuffers, which only releases buffers once their segments are no longer referenced by committed messages.

Removing the eager-free would, on its own, expose a pre-existing buffer leak: for a message too large to ever fit in a pooled buffer, the eager-free was the only thing that reclaimed the freshly allocated (and never-committed) block. To close that, the EventHub, Memory and Generator caches now dispose the freshly allocated block back to the pool and throw before registering it with the eviction strategy, so repeated oversized (poison) messages reuse a single block instead of growing the retained set without bound.

Adds regression tests for multi-buffer batch payload integrity from an empty cache and for the oversized-message no-leak behavior. Both fail without the fix and pass with it.

Microsoft Reviewers: Open in CodeFlow

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ReubenBond
fix(streaming): don't recycle in-flight pooled buffers mid-batch
6330925
The chronological eviction strategy eagerly freed the previous pooled
buffer whenever the cache was empty (PurgeObservable.IsEmpty). Because
callers encode an entire batch into pooled buffers before committing it,
IsEmpty stays true throughout the encode and the buffer being freed can
still hold in-flight, uncommitted segments for the current batch. The
freed buffer is returned to the LIFO pool and the next allocation in the
same batch pops it straight back, overwriting the earlier segments from
offset 0 and silently corrupting payloads (surfacing later as an
ArgumentOutOfRangeException in SegmentBuilder.ReadNextString).

Remove the eager-free branch; buffers are reclaimed safely at purge time
by FreePurgedBuffers. This affects all three pooled caches (EventHub,
Memory, Generator), which share this eviction strategy.

Removing the eager-free would expose a pre-existing buffer leak for
oversized messages, since it was the only thing that reclaimed a freshly
allocated block when a message was too big to ever fit. The EventHub,
Memory and Generator caches now dispose the freshly allocated block back
to the pool and throw before registering it with the eviction strategy,
so repeated oversized (poison) messages reuse a single block instead of
growing the retained set without bound.

Adds regression tests covering multi-buffer batch payload integrity and
the oversized-message no-leak behavior.

Fixes dotnet#10263

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 577af892-8411-4f35-9b87-55ad42b0d059
@azure-pipelines

azure-pipelines Bot commented Jul 15, 2026

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ReubenBond
ReubenBond requested a review from Copilot July 15, 2026 16:36
Copilot started reviewing on behalf of ReubenBond July 15, 2026 16:36
View session
Copilot AI reviewed Jul 15, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a streaming buffer-corruption bug in Orleans’ pooled queue cache infrastructure by preventing in-flight pooled buffers from being recycled mid-batch, and adds regression tests to cover the corruption scenario plus an oversized-message buffer leak.

Changes:

  • Removed eager buffer recycling in ChronologicalEvictionStrategy.OnBlockAllocated to avoid returning still-in-use buffers to the pool mid-batch.
  • Updated EventHub/Memory/Generator pooled caches (and the test converter) to validate segment fit before registering a new buffer with the eviction strategy, disposing the unused buffer on failure to avoid leaks.
  • Added regression tests validating multi-buffer batch payload integrity from an empty cache and ensuring repeated oversized messages do not leak buffers.
Show a summary per file
File Description
test/Orleans.Streaming.Tests/OrleansRuntime/Streams/PooledQueueCacheTests.cs Adds regression tests for mid-batch corruption and oversized-message non-leak; updates test converter allocation order accordingly.
src/Orleans.Streaming/MemoryStreams/MemoryPooledCache.cs Disposes newly-allocated buffers on oversized-message failure before eviction registration to prevent leaks.
src/Orleans.Streaming/Generator/GeneratorPooledCache.cs Same oversized-message no-leak allocation ordering fix for generator cache.
src/Orleans.Streaming/Common/PooledCache/ChronologicalEvictionStrategy.cs Removes eager-free logic from OnBlockAllocated to prevent recycling in-flight buffers while cache is “empty”.
src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubQueueCache.cs Same oversized-message no-leak allocation ordering fix for EventHub queue cache.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 3

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubQueueCache.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Orleans.Streaming/Generator/GeneratorPooledCache.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/Orleans.Streaming.Tests/OrleansRuntime/Streams/PooledQueueCacheTests.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ReubenBond
refactor(streaming): address PR review nits
024c62c
Fix 'to big' -> 'too big' typo in the EventHub and Generator oversized-message exception messages, matching the Memory cache, and make the test TestQueueMessage.Data an init-only property so per-message payloads can't be mutated after construction.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 577af892-8411-4f35-9b87-55ad42b0d059
@ReubenBond
ReubenBond merged commit 86c7b4c into dotnet:main Jul 15, 2026
61 of 62 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ReubenBond
ReubenBond deleted the reubenbond-issue-10263-fixedsizebuffer-recycle branch July 15, 2026 16:45
This was referenced Jul 22, 2026
[Dependency] Bump the actions group with 10 updates XtremeOwnage/rPDU2MQTT#236
Merged
Bump the orleans group with 3 updates microsoft/aspire-samples#1823
Merged
Bump Microsoft.Orleans.Client and 8 others intochat/intochat#43
Closed
Bump the orleans group with 1 update vgmello/momentum#308
Closed
This was referenced Jul 29, 2026
Bump the dotnet group with 6 updates IvanMarkitan/dotnet-docs#217
Closed
Bump the dotnet group with 4 updates IvanMarkitan/dotnet-docs#220
Closed
Bump the dotnet group with 7 updates IvanMarkitan/dotnet-docs#228
Closed
Bump Microsoft.Extensions.Logging.Abstractions and 3 others IvanMarkitan/dotnet-docs#236
Closed
Bump Microsoft.Orleans.Sdk and Microsoft.Orleans.Server IvanMarkitan/dotnet-docs#238
Closed
Bump Microsoft.Orleans.Clustering.Redis and 4 others IvanMarkitan/dotnet-docs#241
Closed
Bump the dotnet group with 6 updates IvanMarkitan/dotnet-docs#258
Closed
Bump the dotnet group with 6 updates BillWagner/docs#9268
Closed
Bump the dotnet group with 6 updates BillWagner/docs#9269
Closed
Bump the dotnet group with 5 updates BillWagner/docs#9271
Closed
Bump the dotnet group with 9 updates BillWagner/docs#9286
Closed
Bump the dotnet group with 6 updates zbalkan/docs#1673
Closed
Bump the dotnet group with 7 updates zbalkan/docs#1677
Closed
Bump the dotnet group with 4 updates zbalkan/docs#1684
Closed
Bump Microsoft.Orleans.Sdk and Microsoft.Orleans.Server zbalkan/docs#1690
Closed
Bump Microsoft.Orleans.Clustering.Redis and 4 others zbalkan/docs#1760
Closed
Bump the dotnet group with 6 updates zbalkan/docs#1761
Closed
Bump the dotnet group with 6 updates dotnet/docs#55175
Merged
This was referenced Jul 29, 2026
Bump the dotnet group with 6 updates dotnet/docs#55176
Merged
Bump the dotnet group with 5 updates dotnet/docs#55177
Merged
Bump the dotnet group with 9 updates dotnet/docs#55178
Merged
Bump the orleans group with 10 updates bartul/agave#75
Closed
Bump the orleans group with 4 updates rick-dev-creator/Observa#28
Open
Bump Microsoft.Orleans.Clustering.AzureStorage from 10.2.1 to 10.2.2 en-gen/Wayfinder#210
Open
Bump Microsoft.Orleans.EventSourcing from 10.2.1 to 10.2.2 en-gen/Wayfinder#211
Open
Bump Microsoft.Orleans.Persistence.AzureStorage from 10.2.1 to 10.2.2 en-gen/Wayfinder#212
Open
Bump Microsoft.Orleans.Reminders and Microsoft.Orleans.Sdk en-gen/Wayfinder#213
Closed
Bump Microsoft.Orleans.Reminders and Microsoft.Orleans.Reminders.AzureStorage en-gen/Wayfinder#214
Merged
Bump Microsoft.Orleans.Sdk from 10.2.1 to 10.2.2 en-gen/Wayfinder#215
Closed
Bump Microsoft.Orleans.Clustering.Redis and 4 others IvanMarkitan/dotnet-docs#351
Closed
Bump Microsoft.Orleans.Clustering.Redis and 4 others zbalkan/docs#1868
Closed
@dependabot dependabot Bot mentioned this pull request Aug 11, 2026
Bump Microsoft.Orleans.Sdk from 10.2.0 to 10.2.2 Mystikweb/Orleans.Streams.Confluent#23
Closed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

EventHub streaming: FixedSizeBuffer recycled mid-batch corrupts cached segments (ArgumentOutOfRangeException in SegmentBuilder.ReadNextString)

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ReubenBond
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.