You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Detect multiple memory mapped to the same file on Browser and throw exception #39428
Hi @carlossanlop, PR #39355 does not fix the issue. The tests disabled in the PR with [PlatformSpecific(~TestPlatforms.Browser)] such as ViewsShareData in src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewStream.Tests.cs still have issues with multiple MemoryMappedFiles accessing the same file.
After looking into this issue more, resolving without introducing new public methods doesn't seem likely at the moment, hence changing the milestone from 5.0.0 to Future.
One of the problems is that when a MMF (MemoryMappedFile) opens multiple MMVS (MemoryMappedViewStream), if one MMVS writes to the MMF, the other MMVS does not see the changes.
Our solution was to throw NotSupportedException when trying to write to a MMF that has multiple MMVS open. Writing to a MMF occurs from the MMVS side (plus others in note below), so to prevent writing, the MMVS must know how many MMVS were opened by its MMF at the time of writing. However, in the MemoryMappedFile class there was no existing attribute or method to tell how many MMVS the MMF opened, so a public method would need to be introduced in order to inform the MMVS, which is not possible for 5.0.0.
Note: Writing to a MemoryMappedFile encompasses more than just writing from a MemoryMappedViewStream. As MemoryMappedViewStream inherits from UnmanagedMemoryStream, it has Write, WriteAsync, WriteByte available. Furthermore, it seems that MemoryMappedFiles can also open MemoryMappedViewAccessor, which also has the potential to write to the MemoryMappedFile via Write and WriteArray. To properly prevent writing when a MemoryMappedFile opens more than just one view stream or accessor, all of these would need to be considered.
Activity
carlossanlop commentedon Jul 29, 2020
@akoeplinger can you confirm if PR #39355 fixed this issue? If yes, can you please close this?
mdh1418 commentedon Jul 29, 2020
Hi @carlossanlop, PR #39355 does not fix the issue. The tests disabled in the PR with
[PlatformSpecific(~TestPlatforms.Browser)]such asViewsShareDatainsrc/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewStream.Tests.csstill have issues with multipleMemoryMappedFilesaccessing the same file.carlossanlop commentedon Jul 29, 2020
Ah I see, thanks for clarifying. The order in which the issue and PR were created confused me.
Does it make sense to have this issue marked for 5.0?
steveisok commentedon Jul 30, 2020
Yeah. it does seem doable for 5.0.
mdh1418 commentedon Aug 3, 2020
After looking into this issue more, resolving without introducing new public methods doesn't seem likely at the moment, hence changing the milestone from
5.0.0toFuture.One of the problems is that when a MMF (
MemoryMappedFile) opens multiple MMVS (MemoryMappedViewStream), if one MMVS writes to the MMF, the other MMVS does not see the changes.Our solution was to throw
NotSupportedExceptionwhen trying to write to a MMF that has multiple MMVS open. Writing to a MMF occurs from the MMVS side (plus others in note below), so to prevent writing, the MMVS must know how many MMVS were opened by its MMF at the time of writing. However, in theMemoryMappedFileclass there was no existing attribute or method to tell how many MMVS the MMF opened, so a public method would need to be introduced in order to inform the MMVS, which is not possible for5.0.0.Note: Writing to a MemoryMappedFile encompasses more than just writing from a MemoryMappedViewStream. As MemoryMappedViewStream inherits from
UnmanagedMemoryStream, it hasWrite,WriteAsync,WriteByteavailable. Furthermore, it seems that MemoryMappedFiles can also open MemoryMappedViewAccessor, which also has the potential to write to the MemoryMappedFile viaWriteandWriteArray. To properly prevent writing when a MemoryMappedFile opens more than just one view stream or accessor, all of these would need to be considered.akoeplinger commentedon Feb 3, 2025
Given the comment above I think we can close this as "won't fix", I don't remember anybody complaining about this so far.