statfs
/statvfs
calls in native impl. for SystemNative_GetFormatInfoForMountPoint
(via [System.IO.DriveInfo]::GetDrives()
) hangs when run against a disconnected network mountpoint
#113098
Labels
Description
NOTE: I consistently say that call will hang "forever": I found that if you bring back the connection, the programs/PowerShell will (eventually) resolve or exit/die. This can take a while.
Running
[System.IO.DriveInfo]::GetDrives()
will hang on trying to determinea mount type (Fixed, Network, ...)some property of the mount (apart from the name) when, on Linux, a network mount has been disconnected (but is still mounted). This is because it eventually calls down tostatfs(2)
/statvfs(3)
, which will hang the caller (I haven't tested for how long).The following is specifically for the
DriveType
property & follows along with the C# example below, but probably applies to the others as well:In asking for
drive.DriveType
, the getter calls toInterop.Sys.GetFormatInfoForMountPoint
runtime/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Unix.cs
Line 17 in 9c8ec9c
runtime/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs
Lines 48 to 51 in 9c8ec9c
, who redirects to
runtime/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs
Lines 36 to 41 in 9c8ec9c
, which calls out to a native C method
SystemNative_GetFormatInfoForMountPoint
runtime/src/native/libs/System.Native/pal_mount.c
Lines 134 to 136 in 9c8ec9c
This calls into either
statfs(2)
runtime/src/native/libs/System.Native/pal_mount.c
Line 142 in 9c8ec9c
statvfs(3)
runtime/src/native/libs/System.Native/pal_mount.c
Line 145 in 9c8ec9c
Reproduction Steps
Repro steps are included for PowerShell, C (at the end), and C#.
To reproduce the hanging within the runtime:
This can be reproduced with PowerShell with minimal effort, through C (for the base error), or through C#, though you need to make a project for this.
If you are actively using your terminal, spawn a new instance. Once the problem is created, PowerShell cannot be killed (no Ctrl+C or
kill -9
!) and under certain terminals (I use KDE's Konsole) it may eventually freeze the entire window. The hung PowerShell instance can only be killed by closing the terminal window.Build the executable.
When running, if you are actively using your terminal, spawn a new instance. Once the problem is created, the program cannot be killed (no Ctrl+C or
kill -9
!), but can be stopped by closing your terminal/terminal tab (at least on KDE's Konsole).For PowerShell, run the following code:
[io.driveinfo]::getdrives()
Everything will list normally. For me, my mounted drive is always at the end, so it looks like this:
For C#, run the executable. Everything will list normally. For me, my mounted drive is always at the end, so it looks like this:
Turn off your network connection (airplane mode,
rfkill
, physical unplug, etc...).Run the code again. Both will freeze while writing the details of the mountpoint.
For PowerShell,
, and C#,
To reproduce the pure hanging in C
When running the program, if you are actively using your terminal, spawn a new instance. Once the problem is created, the program cannot be killed (no Ctrl+C or
kill -9
!), but can be stopped by closing your terminal/terminal tab (at least on KDE's Konsole).gcc <filename>.c
a.out <fs or vfs, run with each> <mountpoint>
It will output something like
or
where the result is 0 for success and -1 for an error (this will not indicate the hanging)
5. Turn off your network connection (airplane mode,
rfkill
, physical unplug, etc...).6. Run the program again. It will freeze and not output anything.
Or
You can also just run
stat <mountpoint>
in a shell while it's disconnected.Expected behavior
[System.IO.DriveInfo]::GetDrives()
should not hang forever when the mountpoint it is scanning is disconnected. Maybe it could time out after some time?Actual behavior
[System.IO.DriveInfo]::GetDrives()
hangs forever.Regression?
No idea
Known Workarounds
No idea
Configuration
Other information
(mentioned in description)
The text was updated successfully, but these errors were encountered: