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

ArrayMemoryPool.ArrayMemoryPoolBuffer implementation of ref counting isn't thread safe #25235

Closed
davidfowl opened this issue Feb 28, 2018 · 8 comments

Comments

@davidfowl
Copy link
Member

We're not using interlocked for some reason here and we should be https://github.com/dotnet/corefx/blob/865f08623bd493fb6d239530e00db29bf6736330/src/System.Memory/src/System/Buffers/ArrayMemoryPool.ArrayMemoryPoolBuffer.cs#L80-L98. This could potentially lead to leaks.

/cc @jkotas @atsushikan @ahsonkhan @pakrym @KrzysztofCwalina

@pakrym
Copy link
Contributor

pakrym commented Feb 28, 2018

This needs to get into preview2

@stephentoub
Copy link
Member

See the discussion here:
dotnet/corefx#26563 (review)

@davidfowl
Copy link
Member Author

These counts need to be accurate, it's not only about use after free (I missed that discussion), the way pipelines uses them relies on this reference counting to return to the pool. If it stays this way we'll keep our own reference count and ignore the Retain/Release semantics of OwnedMemory<T> which would make me a sad 🐼

@jkotas
Copy link
Member

jkotas commented Feb 28, 2018

This could potentially lead to leaks.

From the usage pattern you are describing, it can also lead to use-after-free bugs. Use-after-free bugs are security bugs - much worse than leaks.

@davidfowl
Copy link
Member Author

Agreed 😄. Here's a related bug https://github.com/dotnet/corefx/issues/27544.

@joshfree joshfree assigned ghost Mar 7, 2018
@KrzysztofCwalina
Copy link
Member

@atsushikan, is this fixed? If yes, please close.

@ghost
Copy link

ghost commented Mar 20, 2018

@davidfowl - Pls confirm that dotnet/corefx#27615 addresses your needs (and that we've decided what the semantics are :))

@davidfowl
Copy link
Member Author

davidfowl commented Mar 21, 2018

Yep, this is good to close

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants