Skip to content

Fix MemoryPool<byte>.Shared.MaxBufferSize seems incorrect - #61755

Merged
jeffhandley merged 1 commit into
dotnet:mainfrom
teo-tsirpanis:fix-61560
Jun 24, 2022
Merged

jeffhandley merged 1 commit into
dotnet:mainfrom
teo-tsirpanis:fix-61560

Conversation

@teo-tsirpanis

@teo-tsirpanis teo-tsirpanis commented Nov 17, 2021 •

Copy link
Copy Markdown
Contributor

ArrayMemoryPool.MaxBufferSize's value was changed to Array.MaxLength.

Fixes #61560

`ArrayMemoryPool.MaxBufferSize`'s value was changed to `Array.MaxLength`.
@ghost ghost added the area-System.Buffers label Nov 17, 2021
@ghost

ghost commented Nov 17, 2021

Copy link
Copy Markdown

Tagging subscribers to this area: @GrabYourPitchforks, @dotnet/area-system-buffers
See info in area-owners.md if you want to be subscribed.

Issue Details

ArrayMemoryPool.MaxBufferSize's value was changed to Array.MaxLength.

Author: teo-tsirpanis
Assignees: -
Labels:

area-System.Buffers

Milestone: -

@GrabYourPitchforks

Copy link
Copy Markdown
Member

@bartonjs @ericstj Is there a compat concern here? Scenario:

int len = int.MaxValue;
try
{
    MemoryPool<byte>.Shared.Rent(len);
}
catch (OutOfMemoryException)
{
    /* swallow */
}

In .NET 6 and earlier, an OOM would be thrown, and it would be caught and swallowed. With the proposed change here, it's instead an ArgumentOutOfRangeException, so the exception would continue to propagate up the stack.

MSDN doesn't exactly specify which exceptions come from MemoryPool<T>.Rent, but we know from experience that OutOfMemoryException is frequently special-cased in real-world applications.

I'd appreciate your thoughts on my level of paranoia here.

@danmoseley danmoseley changed the title Fix #61560. Fix MemoryPool<byte>.Shared.MaxBufferSize seems incorrect Dec 13, 2021
@danmoseley

Copy link
Copy Markdown
Contributor

@teo-tsirpanis if you put "fixes #61560" in the top comment, Github will close it for you when this merges.

@danmoseley

Copy link
Copy Markdown
Contributor

@marklio thoughts about the breaking change concern here? It seems to me this exception would never be expected by user code - it would always be a bug in the code - as well as perhaps unlikely case, so this seems reasonable to put in a sxs release.

@jeffhandley

Copy link
Copy Markdown
Member

@michaelgsharp I've assigned this to you to check in on after the new year and to help shepherd this through to merge or closure.

@deeprobin deeprobin 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.

LGTM.

@jeffhandley jeffhandley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I echo @danmoseley's comment about this being an acceptable change to the exception that could be thrown, and I support this change going through.

Thanks for the contribution, @teo-tsirpanis; sorry for the delay getting it merged.

@jeffhandley
jeffhandley merged commit 77a714d into dotnet:main Jun 24, 2022
@teo-tsirpanis
teo-tsirpanis deleted the fix-61560 branch June 24, 2022 23:32
@ghost ghost locked as resolved and limited conversation to collaborators Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MemoryPool<byte>.Shared.MaxBufferSize seems incorrect

6 participants