Ignore FileStream.FlushWriteBuffer failures during finalization
authorStephen Toub <stoub@microsoft.com>
Tue, 14 Mar 2017 12:30:24 +0000 (08:30 -0400)
committerStephen Toub <stoub@microsoft.com>
Tue, 14 Mar 2017 12:30:24 +0000 (08:30 -0400)
Commit migrated from https://github.com/dotnet/coreclr/commit/3b01f961ae369b4a61f0dc30bc647bdc7ea2d3b0

src/coreclr/src/mscorlib/shared/System/IO/FileStream.Unix.cs

index 87bcc6c..ef186ff 100644 (file)
@@ -230,7 +230,15 @@ namespace System.IO
                 if (_fileHandle != null && !_fileHandle.IsClosed)
                 {
                     // Flush any remaining data in the file
-                    FlushWriteBuffer();
+                    try
+                    {
+                        FlushWriteBuffer();
+                    }
+                    catch (IOException) when (!disposing)
+                    {
+                        // On finalization, ignore failures from trying to flush the write buffer,
+                        // e.g. if this stream is wrapping a pipe and the pipe is now broken.
+                    }
 
                     // If DeleteOnClose was requested when constructed, delete the file now.
                     // (Unix doesn't directly support DeleteOnClose, so we mimic it here.)