-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET 6 regression on writing to character device #59754
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsCreate a console app with following content in Program.cs: using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
string path = "/dev/tty";
if (!File.Exists(path))
{
throw new Exception(path + " is not available in this environment.");
}
var contentBytes = new byte[] { 1, 2, 3 };
using (var cts = new CancellationTokenSource())
{
Task writingTask = File.WriteAllBytesAsync(path, contentBytes, cts.Token);
cts.CancelAfter(TimeSpan.FromMilliseconds(500));
await writingTask;
}
Console.WriteLine("Passed!"); On macOS (x64), run with .NET 5 (5.0.400), it prints
|
This is not reproducible on Linux with .NET 6, so macOS (and likely other non-Linux Unices) are affected. |
Output of ^ @tmds, |
Your stacktrace is different:
This is interesting:
.NET does this to find out whether the file is 'seekable'. On Linux this fails with That determines whether bytes are written using runtime/src/libraries/System.Private.CoreLib/src/System/IO/RandomAccess.Unix.cs Lines 93 to 95 in 8e4c996
So on Linux this uses |
I mean from the one in CI on #58434 which fails on |
On macOS, I can reproduce that test failure with same stacktrace locally.
I am still building PR branch on Ubuntu, but I have a theory the test is failing on Linux with |
The root cause is that I see two options:
@stephentoub @am11 @jozkee @carlossanlop @adamsitnik do you prefer one of these options? or see other options? |
Why |
Could there be any perf. regressions in doing this? I assume perf. was the main reason why we changed to pread/pwrite. |
Perhaps a bit more defensive approach: |
I don't know how to fix I think it's better to do this based on the
I think not. It impacts the ordering of concurrent reads/writes, which is well defined when using Personally, I think users should be using
|
We should do:
We plan to allow RandomAccess to be used with arbitrary file handles, not just seekable ones, and not just unseekable ones from FileStream, e.g. |
@stephentoub so should the plan be to merge the PR #58506 and then backport it to 6.0? If so, do you think is far from merging? In the other hand, I would prefer @tmds's suggested fix since is minimal and less risky to backport. |
Fix has landed in 6.0.100-rtm.21514.1. Thanks @jozkee! 🎉 |
Create a console app with following content in Program.cs:
On macOS (x64), run with .NET 5 (5.0.400), it prints
Passed!
. In .NET 6 (6.0.100-rtm.21479.10) it throws:The text was updated successfully, but these errors were encountered: