Skip to content

Detect multiple memory mapped to the same file on Browser and throw exception #39428

Closed as not planned

Description

@akoeplinger

In #39355 a few tests were disabled since multiple mmap() to the same file don't result in data being shared in emscripten's VFS implemenation.

We should investigate whether we can detect that and throw a proper NotSupportedException.

Activity

  1. added this to the 5.0.0 milestone on Jul 16, 2020
  2. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 16, 2020
  3. carlossanlop commented on Jul 29, 2020

    @carlossanlop
    Contributor

    @akoeplinger can you confirm if PR #39355 fixed this issue? If yes, can you please close this?

  4. mdh1418 commented on Jul 29, 2020

    @mdh1418
    Member

    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.

  5. carlossanlop commented on Jul 29, 2020

    @carlossanlop
    Contributor

    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?

  6. steveisok commented on Jul 30, 2020

    @steveisok
    Member

    Yeah. it does seem doable for 5.0.

  7. modified the milestones: 5.0.0, Future on Aug 3, 2020
  8. mdh1418 commented on Aug 3, 2020

    @mdh1418
    Member

    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.

  9. akoeplinger commented on Feb 3, 2025

    @akoeplinger
    MemberAuthor

    Given the comment above I think we can close this as "won't fix", I don't remember anybody complaining about this so far.

  10. removed this from the Future milestone on Feb 3, 2025
  11. locked and limited conversation to collaborators on Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions