Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify buffer overflow logic for System.Buffers.ArrayPool.Tests.ArrayPoolUnitTests.ReturnBufferWhenFullFiresDroppedDiagnosticEvent #112849

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Venkad000
Copy link

The test 'System.Buffers.ArrayPool.Tests.ArrayPoolUnitTests.ReturnBufferWhenFullFiresDroppedDiagnosticEvent' fails on systems with cpu cores >= 32.

The test begins by renting from a SharedArrayPool 1 byte using the 'Rent' function for 1000 iterations and returning the bytes rented using the 'Return' function back to the SharedArrayPool.

The test expects that returning a large number of bytes(in this case 1000) overflows the SharedArrayPool hence dropping it. The test case fails in machines that have cpu cores greater than 32 because the capacity of the SharedArrayPool is dependent on the number of processors. It happens to be 'number of processors' * 32.

The size of the SharedArrayPool in case of 32 cpu cores would be 32*32=1024 which is greater than 1000 and hence doesn't overflow the SharedArrayPool and hence failing test case. We actualy need ('number of processors' * 32 + 2) iterations because ('number of processors' * 32 + 1) bytes would be required to overflow the buffer and the ith iteration actually caches the byte to TLA and push the (i-1)th byte to the pool. Hence ('number of processors + 32' + 1)th byte would be returned on the ('number of processors + 32' + 2)nd iteration. see link

…ferWhenFullFiresDroppedDiagnosticEvent' fails on systems with cpu cores >= 32.

The test begins by renting from a SharedArrayPool 1 byte using the 'Rent' function for 1000 iterations and returning the bytes rented using the 'Return' function back to the SharedArrayPool. The test expects
that returning a large number of bytes(in this case 1000) overflows the SharedArrayPool hence dropping it. The test case fails in machines that have cpu cores greater than 32 because the capacity of the SharedArrayPool is dependent on the number
of processors. It happens to be 'number of processors' * 32. Clearly the size of the SharedArrayPool in case of 32 cpu cores would be 32*32=1024 which is greater than 1000 and hence doesn't overflow the
SharedArrayPool and hence failing test case. We actualy need ('number of processors' * 32 + 2) iterations because ('number of processors' * 32 + 1) bytes would be required to overflow the buffer and the ith
iteration actually caches the byte to TLA and push the (i-1)th byte to the pool. Hence ('number of processors + 32' + 1)th byte would be returned on the ('number of processors + 32' + 2)nd iterations.
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 24, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 24, 2025
@Venkad000
Copy link
Author

cc: @uweigand @giritrivedi @saitama951

Copy link
Contributor

@giritrivedi giritrivedi left a comment

Choose a reason for hiding this comment

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

LGTM

@huoyaoyuan huoyaoyuan added area-System.Buffers and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 24, 2025
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Buffers community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants