-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
new FileStream(fd,..., isAsync:true)
doesn't appear to be supported on Unix
#85560
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsI don't appear to have any supported way to create a new FileStream from a raw int FD on Linux with async set to true. It's easy enough for me to call open() with O_ASYNC. The next step would be to create a SafeFileHandle, and then hand it to the ctor of FileStream. However, SafeFileHandle's Unix implementation seems to have no way to tell it the underlying FD is async. The Windows version calls into ntdll to actually detect whether the FD is async. The Unix version doesn't have any such call, and only sets IsAsync when it is responsible for calling open(). However, new FileStream(sfh,,,true) validates that IsAsync on the SafeFileHandle is true. FileStream(IntPtr...true) seems to work, but is marked deprecated.
|
new FileStream(fd, isAsync:true)
doesn't appear to be supported on Unixnew FileStream(fd,..., isAsync:true)
doesn't appear to be supported on Unix
…ReadAsync can be positional, and FileStream WriteAsync/ReadAsync isn't exactly thread safe on all platforms (sorta was on Core, but is no longer on NET 6, they added RandomFileAccess), we need a lock around the FD for these operations (position can change between set position and write). This can be fixed by going after the underlying IO directly, but this code is already built around FileStream. So, basically, these AIO methods are now queued per file. .NET 6 however has a problem. No ability to create a FileStream from a FD on Unix with async: dotnet/runtime#85560 So, we go directly to the private IsAsync field if it exists and set it. Hack. This mismatch between .NET and Java expectations for IO strike again.
It appears that you can query the flags set on a given file descriptor using |
Hi @wasabii
From https://man7.org/linux/man-pages/man2/open.2.html
If you are using sockets please use Socket type that provides full async support on Linux (via epoll). In the future we might implement |
At the OS level that might all be true, however, and I might be not completely accurate here anymore, because I'd have to fire up my tests again, it's been awhile.... I found that FileStream.ReadAsync/WriteAsync and similar methods were unusable unless FileStream thought it was talking to an async handle. They threw. So, even though FileStream.ReadAsync would technically function on Unix by doing synchronous operations: it refused to do so unless it thought it was opened for async operations. And the only way to create a new FileStream that thought it was capable of doing so, from a FD, was to pass it a SafeFileHandle marked for isAsync. Ignore O_ASYNC, as I suppose that was somewhat of a red herring for my purposes here. I need a FileStream that is capable of having ReadAsync called on it. And I need to initialize that FileStream from a FD. And there is no option to create a FileStream with isAsync: true, if the SafeFileHandle.IsAsync is false. |
These methods should always work no matter how you create the @wasabii Which .NET version are you using? Could you please provide a repro? |
I don't appear to have any way to create a new FileStream from a raw int FD on Linux with async set to true. It's easy enough for me to call open() with O_ASYNC. The next step would be to create a SafeFileHandle, and then hand it to the ctor of FileStream. However, SafeFileHandle's Unix implementation seems to have no way to tell it the underlying FD is async. The Windows version calls into ntdll to actually detect whether the FD is async. The Unix version doesn't have any such call, and only sets IsAsync when it is responsible for calling open().
However, new FileStream(sfh,,,true) validates that IsAsync on the SafeFileHandle is true.
The text was updated successfully, but these errors were encountered: