Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Remove problematic ArrayPool usage #6473

Merged
merged 1 commit into from
Feb 26, 2016

Conversation

stephentoub
Copy link
Member

We decided in the design meeting today that we should only be using ArrayPool in corefx itself in places where we can guarantee the types/methods won't cause corruption, even if due to misuse. Some of the usage we've already put in place doesn't meet this bar and needs to be removed. For example, we use ArrayPool<byte>.Shared in a special CopyToAsync implementation, but in doing so we hand a buffer from the pool out to the constiuent streams, and a poorly behaving stream could end up holding on to the buffer even after CopyToAsync has returned to the pool, such as if a Stream.WriteAsync implementation had a bug and completed the returned task before it was actually done with the buffer.

This commit removes all such usage (which we only very recently added). There is one usage of ArrayPool<char>.Shared left in corefx, in ZipFile, which meets the bar, as the buffer is never handed out to code outside of the class, is used in a scoped manner on the stack, etc.

cc: @sokket, @KrzysztofCwalina, @jkotas
Fies #6472

We decided in the design meeting today that we should only be using ArrayPool in corefx itself in places where we can guarantee the types/methods won't cause corruption, even if due to misuse. Some of the usage we've already put in place doesn't meet this bar and needs to be removed.   For example, we use ```ArrayPool<byte>.Shared``` in a special CopyToAsync implementation, but in doing so we hand a buffer from the pool out to the constiuent streams, and a poorly behaving stream could end up holding on to the buffer even after CopyToAsync has returned to the pool, such as if a Stream.WriteAsync implementation had a bug and completed the returned task before it was actually done with the buffer.

This commit removes all such usage (which we only very recently added).
@jonmill
Copy link

jonmill commented Feb 26, 2016

It makes me sad that these perf gains have to go away, but LGTM

@KrzysztofCwalina
Copy link
Member

We should consider adding similar APIs that just take an array parameter to be used as the intermediate buffer.

@jkotas
Copy link
Member

jkotas commented Feb 26, 2016

LGTM

@stephentoub
Copy link
Member Author

We should consider adding similar APIs that just take an array parameter to be used as the intermediate buffer.

Yes, or the pool to use. Can you open an issue, @KrzysztofCwalina?

LGTM

Thanks for the reviews.

stephentoub added a commit that referenced this pull request Feb 26, 2016
@stephentoub stephentoub merged commit 9cc4f66 into dotnet:master Feb 26, 2016
@stephentoub stephentoub deleted the remove_buffer_usage branch February 26, 2016 21:36
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…usage

Remove problematic ArrayPool usage

Commit migrated from dotnet/corefx@9cc4f66
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants