Skip to content

[release/6.0] Make sure that shared memory object name meets the length requiremens - #64266

Merged
safern merged 1 commit into
dotnet:release/6.0from
adamsitnik:backportMemoryMappedFilesFix
Feb 7, 2022
Merged

[release/6.0] Make sure that shared memory object name meets the length requiremens#64266
safern merged 1 commit into
dotnet:release/6.0from
adamsitnik:backportMemoryMappedFilesFix

Conversation

@adamsitnik

@adamsitnikadamsitnik commented Jan 25, 2022

Copy link
Copy Markdown
Member

A manual backport of #64099

The sys-call that we use to create shared memory mapped objects (shm_open) has distro-specific map name length requirements. On most Unix-like Operating Systems it's PATH_MAX (4096), while on macOS it's SHM_NAME_MAX which for the arm64 version currently maps to 32. The code has been simply generating a string that is too long.

Customer Impact

Customer reported #63240 in 6.0. macOS arm64 users can't create a memory mapped file which is not backed by a real file (MemoryMappedFile.CreateNew(mapName: null)) . There is no workaround.

Testing

The tests have been.. re-enabled. Yes, we had failing tests that were clearly saying that there is a bug but they got disabled rather than fixed.

Risk

Low. By reducing the map name length we have reduced the entropy so chances for generating a name that is already in use have increased. However, a simple retry logic was added and it ensures that even if a shared map object with a given name already exists, a new name is generated and the process is repeated until it succeeds (or fails for other reasons).

dotnet#64099)
Co-authored-by: Stephen Toub <stoub@microsoft.com>
# Conflicts:
#	src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateNew.Tests.cs
#	src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewAccessor.Tests.cs
#	src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewStream.Tests.cs
#	src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewStreamConformanceTests.cs
@ghost

Copy link
Copy Markdown

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

Issue Details

A manual backport of #64099

Author:adamsitnik
Assignees:-
Labels:

area-System.IO

Milestone:-

@ghostghost assigned adamsitnikJan 25, 2022
@adamsitnik

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-extra-platforms

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

return null;
}
Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
fd.Dispose();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, it's a little weird to Dispose of the SafeHandle and then continue to use it, but technically in this case it's ok to do so, given how it's being used. It's just unusual to see and thus a little disconcerting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe a comment here would help clarify the unusual usage?

@danmoseley

Copy link
Copy Markdown
Contributor

Could you add a template we could review, before tactics mail?

@adamsitnikadamsitnik added the Servicing-consider Issue for next servicing release review label Jan 25, 2022
@adamsitnik

Copy link
Copy Markdown
MemberAuthor

Could you add a template we could review, before tactics mail?

Done

@danmoseley

Copy link
Copy Markdown
Contributor

Template looks good. I added that its customer reported. Feel free to send mail..

@leecowleecow added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Jan 25, 2022
@leecowleecow added this to the 6.0.3 milestone Jan 25, 2022
@safern
safern merged commit 2168e52 into dotnet:release/6.0Feb 7, 2022
@ghostghost locked as resolved and limited conversation to collaborators Mar 10, 2022
@adamsitnik
adamsitnik deleted the backportMemoryMappedFilesFix branch June 23, 2022 07:14
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.IOServicing-approvedApproved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@adamsitnik@danmoseley@carlossanlop@stephentoub@leecow@safern