Support cancellation on non-blocking fds in FileStream and RandomAccess on Unix
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
https://github.com/dotnet/runtime/pull/125512 added support to FileStream/RandomAccess for non-seekable files.
It does not include cancellation support on Unix.
For example, the following program hangs instead of throwing when the cancellation token times out:
```cs
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
// Launch an app that will never complete its output.
SafeFileHandle.CreateAnonymousPipe(out SafeFileHandle outputReadPipe, out SafeFileHandle outputWritePipe);
SafeFileHandle.CreateAnonymousPipe(out SafeFileHandle inputReadPipe, out SafeFileHandle inputWritePipe);
ProcessStartInfo producer = new("cat")
{
StandardInputHandle = inputReadPipe,
StandardOutputHandle = outputWritePipe
};
Process.Start(producer);
inputReadPipe.Dispose();
outputWritePipe.Dispose();
// Read the output with a timeout.
var reader = new StreamReader(new FileStream(outputReadPipe, FileAccess.Read));
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
await reader.ReadToEndAsync(cts.Token);
```
cc @adamsitnik @stephentoub @jkotas
Contributor guide
Assessment
This issue has not been assessed yet.