runtime: MemoryMappedFile.CreateNew on macOS throws System.IO.PathTooLongException

Description

MemoryMappedFile.CreateNew throws a System.IO.PathTooLongException: The specified file name or path is too long, or a component of the specified path is too long. exception when passing in null as the map name (null mapName is required on unix as noted in https://github.com/dotnet/runtime/issues/21863).

Program.cs:

using System.IO.MemoryMappedFiles;

// Passing null as mapNames are not supported for mmf on unix
using var mmf = MemoryMappedFile.CreateNew(null, 1);

When run, will throw:

dotnet run --project MemoryMapIssue
Unhandled exception. System.IO.PathTooLongException: The specified file name or path is too long, or a component of the specified path is too long.
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateSharedBackingObjectUsingMemory(MemoryMappedProtections protections, Int64 capacity, HandleInheritability inheritability)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateSharedBackingObject(MemoryMappedProtections protections, Int64 capacity, HandleInheritability inheritability)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateCore(FileStream fileStream, String mapName, HandleInheritability inheritability, MemoryMappedFileAccess access, MemoryMappedFileOptions options, Int64 capacity)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateNew(String mapName, Int64 capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, HandleInheritability inheritability)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateNew(String mapName, Int64 capacity)
   at Program.<Main>$(String[] args) in /Users/aida/workspace/MemoryMapIssue/Program.cs:line 5

Configuration

  • OS: macOS 12.1
  • Arch: ARM64
dotnet --version
6.0.101
dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
dotnet --list-sdks
6.0.101 [/usr/local/share/dotnet/sdk]

Regression?

Unknown

Other information

Following guidance from https://github.com/dotnet/runtime/issues/21863 which says unix systems do not support named mmf; so passing in null as name.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (11 by maintainers)

Commits related to this issue

Most upvoted comments

It looks like this is causing the FSharp Interactive pad in VSMac to crash on startup.

(lldb) pe
Exception object: 0000000105b56c20
Exception type:   <Unknown>
Message:          Error creating evaluation session: System.IO.PathTooLongException: The specified file name or path is too long, or a component of the specified path is too long.
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateSharedBackingObjectUsingMemory(MemoryMappedProtections protections, Int64 capacity, HandleInheritability inheritability)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateSharedBackingObject(MemoryMappedProtections protections, Int64 capacity, HandleInheritability inheritability)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateCore(FileStream fileStream, String mapName, HandleInheritability inheritability, MemoryMappedFileAccess access, MemoryMappedFileOptions options, Int64 capacity)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateNew(String mapName, Int64 capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, HandleInheritability inheritability)
   at FSharp.Compiler.AbstractIL.Internal.ByteMemory.CreateMemoryMappedFile(ReadOnlyByteMemory bytes) in F:\workspace\_work\1\s\src\absil\bytes.fs:line 330
   at FSharp.Compiler.AbstractIL.ILBinaryReader.seekReadManifestResources@3099.GenerateNext(IEnumerable`1& next) in F:\workspace\_work\1\s\src\absil\ilread.fs:line 3114
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in D:\a\_work\1\s\src\fsharp\FSharp.Core\seqcore.fs:line 372
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System.Collections.IEnumerator.MoveNext() in D:\a\_work\1\s\src\fsharp\FSharp.Core\seqcore.fs:line 404
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at FSharp.Compiler.AbstractIL.ILBinaryReader.seekReadManifestResources(ILMetadataReader ctxt, Boolean canReduceMemory, ReadOnlyByteMemory mdv, PEReader pectxtEager, ReadOnlyByteMemory pevEager) in F:\workspace\_work\1\s\src\absil\ilread.fs:line 3098
   at FSharp.Compiler.AbstractIL.ILBinaryReader.seekReadModule(ILMetadataReader ctxt, Boolean canReduceMemory, PEReader pectxtEager, ReadOnlyByteMemory pevEager, UInt16 peinfo_0, Tuple`2 peinfo_1, Boolean peinfo_2, Boolean peinfo_3, Boolean peinfo_4, Boolean peinfo_5, Boolean peinfo_6, FSharpOption`1 peinfo_7, Boolean peinfo_8, Int32 peinfo_9, Int32 peinfo_10, Int32 peinfo_11, String ilMetadataVersion, Int32 idx) in F:\workspace\_work\1\s\src\absil\ilread.fs:line 1499
   at FSharp.Compiler.AbstractIL.ILBinaryReader.openMetadataReader(String fileName, BinaryFile mdfile, Int32 metadataPhysLoc, Tuple`8 peinfo, PEReader pectxtEager, ReadOnlyByteMemory pevEager, FSharpOption`1 pectxtCaptured, Boolean reduceMemoryUsage) in F:\workspace\_work\1\s\src\absil\ilread.fs:line 3579
   at FSharp.Compiler.AbstractIL.ILBinaryReader.OpenILModuleReader(String fileName, ILReaderOptions opts) in F:\workspace\_work\1\s\src\absil\ilread.fs:line 3961
   at FSharp.Compiler.CompileOps.assembliesThatForwardToPrimaryAssembly@4977-2.Invoke(AssemblyResolution resolvedAssembly) in F:\workspace\_work\1\s\src\fsharp\CompileOps.fs:line 4979
   at Microsoft.FSharp.Primitives.Basics.List.choose[T,TResult](FSharpFunc`2 f, FSharpList`1 xs) in D:\a\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 189
   at Microsoft.FSharp.Collections.ListModule.Choose[T,TResult](FSharpFunc`2 chooser, FSharpList`1 list) in D:\a\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 154
   at FSharp.Compiler.CompileOps.BuildFrameworkTcImports@4943-1.Invoke(Tuple`2 _arg6) in F:\workspace\_work\1\s\src\fsharp\CompileOps.fs:line 4975
   at FSharp.Compiler.AbstractIL.Internal.Library.CancellableModule.bind@707.Invoke(CancellationToken ct) in F:\workspace\_work\1\s\src\absil\illib.fs:line 709
   at FSharp.Compiler.AbstractIL.Internal.Library.CancellableModule.bind@707.Invoke(CancellationToken ct) in F:\workspace\_work\1\s\src\absil\illib.fs:line 708
   at FSharp.Compiler.AbstractIL.Internal.Library.CancellableModule.bind@707.Invoke(CancellationToken ct) in F:\workspace\_work\1\s\src\absil\illib.fs:line 708
   at FSharp.Compiler.AbstractIL.Internal.Library.CancellableModule.runWithoutCancellation[a](Cancellable`1 comp) in F:\workspace\_work\1\s\src\absil\illib.fs:line 752
   at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession..ctor(FsiEvaluationSessionHostConfig fsi, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, Boolean fsiCollectible, FSharpOption`1 legacyReferenceResolver) in F:\workspace\_work\1\s\src\fsharp\fsi\fsi.fs:line 2827

These (45) tests are failing on mono runtime as well -https://github.com/dotnet/runtime/issues/64947. These tests are currently disabled on iOS, MacCatalyst due to similar reason, so it’s not just osx-arm64 issue either.