Commit c9f38ce
Open the file with FileShare.ReadWrite | Delete on Windows for delete-while-mapped
The path-based MemoryMappedFile.CreateFromFile overload internally
opens the file with FileShare.Read. On Windows that blocks any
subsequent open-for-write or open-for-delete on the same file while
we hold the mapping. Callers like FreeTextSuggester build a temp
index, dispose the directory, and then recursively delete the
directory; on Windows that recursive delete fails with
"The process cannot access the file ... because it is being used by
another process" because Windows requires FILE_SHARE_DELETE on the
existing handle for a delete to proceed against an open file.
Switch back to opening our own FileStream so we control the share
flags. We use FileShare.ReadWrite | FileShare.Delete to match the
prior behavior (other writers/deleters can proceed; Windows will
defer the actual unlink until our last close, which is the standard
Unix-like semantic the rest of the framework expects). We still
pass capacity: 0 to CreateFromFile so the framework does its own
size stat — the #1090 race window stays closed. leaveOpen: false
hands the FileStream's lifetime to the MMF, so we don't have to
track it as a SharedMapping field.
Zero-length files are handled up front rather than letting
CreateViewAccessor reject the empty view: we dispose the FileStream
eagerly and return an empty SharedMapping.
Caught by Windows CI: TestFreeTextSuggester.TestBasic and siblings
failed with InvalidOperationException("failed to remove ...") wrapped
around IOException("write.lock ... being used by another process")
on net8.0 / net472 / net48 Windows runners. Linux passed because
Linux's "delete while open" semantics don't depend on the open
handle's share mode.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 899ec1f commit c9f38ce
1 file changed
Lines changed: 47 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
765 | 765 | | |
766 | 766 | | |
767 | 767 | | |
768 | | - | |
769 | | - | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | | - | |
774 | | - | |
775 | | - | |
776 | | - | |
777 | | - | |
778 | | - | |
779 | | - | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
785 | 786 | | |
786 | 787 | | |
787 | 788 | | |
788 | 789 | | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
789 | 801 | | |
790 | 802 | | |
791 | 803 | | |
792 | 804 | | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
793 | 808 | | |
794 | | - | |
795 | | - | |
| 809 | + | |
796 | 810 | | |
797 | 811 | | |
798 | | - | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
799 | 818 | | |
800 | 819 | | |
801 | 820 | | |
802 | 821 | | |
803 | 822 | | |
804 | 823 | | |
805 | | - | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
806 | 832 | | |
807 | 833 | | |
808 | 834 | | |
| |||
0 commit comments