-
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
Getting file descriptor count on macOS throws #65254
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
|
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsDescriptionA known way to get the file descriptor count on macOS is by using The problem is that some file descriptors listed under Reproduction Steps
Expected behaviorThe number of open file descriptors. Actual behavior
Regression?Not sure if it's a regression. Known WorkaroundsManually PInvoke Configurationdotnet 6.0.101, macOS 10.14+, x64 and arm64 Other informationNo response
|
@Therzok what do you propose here? Presumably in the general case, we do want to throw this exception. |
The API implicitly does the evaluation of dir entries and their metadata. Something like directory entry count shouldn't populate the stat information of files, unless it's explicitly requested. The equivalent C code is something like: DIR *dir = opendir("/dev/fd");
struct dirent *entries;
int count = 0;
while ((entries = readdir(dir)) {
count++;
} I'd understand if something like |
This code has been recently refactored by @tmds: What we have in 6.0: runtime/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Unix.cs Lines 45 to 61 in 3d345e0
What we have in 7.0: runtime/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Unix.cs Lines 43 to 58 in e23382c
in theory it should not throw, let me start my Linux machine and check it |
I've added a test that ensures that the bug is not coming back: #65301 |
is this fix planned for backporting to net6.0? if not, any workaround for users? |
Not using .NET APIs. Maybe you can try PInvoking the |
It was introduced in #52235
Yes, and also specific to the special directory of
#60214 is a bugfix PR, it doesn't do much refactoring. There are little things to be left out. I think you should take it as a whole. There was a separate PR to refactor some things: #62721. |
@tmds please excuse me, for some reason I mixed these two PRs |
@kasperk81 in what circumstances have you hit this bug? Is it exactly the same use case? |
I have not received any answers for a month, so I am going to close the issue (it's fixed in 7.0, we currently don't plan to backport it to 6.0) |
None of the questions were directed towards me, so I'm pretty sure the issue should still be open, especially given it's a regression in net6.0 |
@danmoseley @jeffhandley does this meets the bar for backporting to 6.0? |
@Therzok Could you describe the type of application this is impacting for you and whether you'd be able to adopt a preview release of .NET 7.0 to gain the fix? Additionally, it would be helpful if you could validate that the preview .NET 7 releases do in fact address the regression in your scenario. These data help us assess the risk/reward of backporting a fix. Thanks! |
Hey @jeffhandley , thanks for the response!
I work on Visual Studio for Mac. We use this API to check whether we are close to hitting the ridiculously low limit of open file handles (256). There currently is a workaround in place where we count filescriptors in C - did not have one at the time. I'm not sure if publishing a release on top of .NET 7.0 is an option right now. Testing on net7
Yields lsof -p output
Closing as we added a workaround on our end, but having this API work in net6 would be nice. |
Thank you, @Therzok. Since you have the (albeit unfortunate) workaround in place are are unblocked, and the backport isn't 100% straightforward/contained, I'm not inclined to backport the fix. If others report the same issue in a way that they are blocked, that would encourage the backport though. |
Description
A known way to get the file descriptor count on macOS is by using
/dev/fd
. Here is an example implementation in Rust.The problem is that some file descriptors listed under
/dev/fd
are notstat
-able, so they will fail when queried. One example iskqueue
s.Reproduction Steps
Directory.EnumerateFileSystemEntries("/dev/fd").Count();
on macOS.Expected behavior
The number of open file descriptors.
Actual behavior
Regression?
Not sure if it's a regression.
Known Workarounds
Manually PInvoke
opendir
and then iterate withreaddir
.Configuration
dotnet 6.0.101, macOS 10.14+, x64 and arm64
Other information
No response
The text was updated successfully, but these errors were encountered: