-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
In restricted environments such as a container with limited access, shared hosting, chroot and other forms of sandbox, .NET process may not have read permissions on procfs files, while the file may exist. This can lead to UnauthorizedAccessException.
While most of the managed code reading procfs files in the runtime repo found by git grep /proc ':/*.cs' ':/!*[tT]est*' seem to handle unauhorized access case, we should try to make the user-experience consistent and align varied styles where possible. A few examples:
Line 38 in c8ede5c
| catch (UnauthorizedAccessException) |
runtime/src/libraries/Common/src/Interop/Linux/procfs/Interop.ProcFsStat.TryReadStatusFile.cs
Line 149 in c8ede5c
| catch (Exception ex) when (ex is IOException || ex.InnerException is IOException) |
runtime/src/libraries/Common/src/Interop/Linux/procfs/Interop.ProcFsStat.ParseMapModules.cs
Lines 26 to 27 in c8ede5c
| catch (IOException) { } | |
| catch (UnauthorizedAccessException) { } |
Line 36 in c8ede5c
| throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); |
and then there are cases in NetworkInformation, which do not handle the exception at all. Majority of procfs files listed in NetworkInformation/NetworkFiles.cs are read via StringParsingHelpers. Some call sites catch IOException and UnauthorizedAccessException, others don't and it seems unintentional. For instance, GetIcmpV4Statistics and GetTcpIPv4Statistics docs do not mention PlatformNotSupportedException, IOException or UnauthorizedAccessException are the possible exceptions which these APIs can throw, only NetworkInformationException is noted.