Bug 56493

Summary: Windows MMAP doesn't release file
Product: [Mono] Runtime Reporter: Michael DeRoy <michaelde>
Component: JITAssignee: Niklas Therning <niklas.therning>
Status: RESOLVED FIXED    
Severity: major CC: joncham, miguel, mono-bugs+mono, mono-bugs+runtime
Priority: High    
Version: 5.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Standalone Xamarin Studio Project to r

Description Michael DeRoy 2017-05-16 12:03:12 UTC
Created attachment 22196 [details]
Standalone Xamarin Studio Project to r

MMAP on windows does not correctly release the file after it is done. To reproduce, download the standalone xamarin studio test project.

Build and run with .NET framework: We get the expected console output
----------
hello
hello
----------


Build and run with Mono 5.0: We get an I/O error on the second mmap
----------
hello

Unhandled Exception:
System.IO.IOException: Could not open file
  at System.IO.MemoryMappedFiles.MemoryMapImpl.OpenFile (System.String path, System.IO.FileMode mode, System.String mapName, System.Int64& capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options) [0x0001c] in D:\j\workspace\y\repos\mono\mcs\class\System.Core\System.IO.MemoryMappedFiles\MemoryMappedFile.cs:102
  at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, System.IO.FileMode mode, System.String mapName, System.Int64 capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) [0x00056] in D:\j\workspace\y\repos\mono\mcs\class\System.Core\System.IO.MemoryMappedFiles\MemoryMappedFile.cs:177
  at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, System.IO.FileMode mode, System.String mapName) [0x00000] in D:\j\workspace\y\repos\mono\mcs\class\System.Core\System.IO.MemoryMappedFiles\MemoryMappedFile.cs:156
  at ReproMMAPFileOpenBug.MainClass.Main (System.String[] args) [0x0009c] in <217a32d6da324f858f64abcbf08d516d>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Could not open file
  at System.IO.MemoryMappedFiles.MemoryMapImpl.OpenFile (System.String path, System.IO.FileMode mode, System.String mapName, System.Int64& capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options) [0x0001c] in D:\j\workspace\y\repos\mono\mcs\class\System.Core\System.IO.MemoryMappedFiles\MemoryMappedFile.cs:102
  at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, System.IO.FileMode mode, System.String mapName, System.Int64 capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) [0x00056] in D:\j\workspace\y\repos\mono\mcs\class\System.Core\System.IO.MemoryMappedFiles\MemoryMappedFile.cs:177
  at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, System.IO.FileMode mode, System.String mapName) [0x00000] in D:\j\workspace\y\repos\mono\mcs\class\System.Core\System.IO.MemoryMappedFiles\MemoryMappedFile.cs:156
  at ReproMMAPFileOpenBug.MainClass.Main (System.String[] args) [0x0009c] in <217a32d6da324f858f64abcbf08d516d>:0
----------
Comment 1 Niklas Therning 2017-05-16 14:54:17 UTC
A PR with a fix has been submitted: https://github.com/mono/mono/pull/4877
Comment 2 Niklas Therning 2017-05-16 17:40:19 UTC
PR has now been merged. Thanks for reporting this!