dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

"System.UnauthorizedAccessException: Access to the path is denied." from Console.WriteLine on Ubuntu 20.10 #48654

Closed sharpninja closed 12 months ago

sharpninja commented 3 years ago

When writing to the Console on Ubuntu 20.04 from the latest Dotnet Core 5.0 SDK Snap Package, System.UnauthorizedAccessException: Access to the path is denied. is thrown.

You can find affected code at sharpninja/FizzBuzz (look in any of the Dotnet projects under src) and compiled binaries.

Configuration

.Net SDK 5.0.103

> lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.10
Release:        20.10
Codename:       groovy

> inxi -F                  
System:    Host: ##### Kernel: 5.8.0-44-generic x86_64 bits: 64 Console: tty 9 Distro: Ubuntu 20.10 (Groovy Gorilla) 
Machine:   Type: Desktop Mobo: ASRock model: X470 Master SLI/ac serial: <superuser/root required> UEFI: American Megatrends 
           v: P1.50 date: 11/06/2018 
CPU:       Info: 8-Core model: AMD Ryzen 7 2700X bits: 64 type: MT MCP L2 cache: 4096 KiB 
           Speed: 1886 MHz min/max: 2200/3700 MHz Core speeds (MHz): 1: 1885 2: 2017 3: 2195 4: 2151 5: 1888 6: 1891 7: 1886 
           8: 1888 9: 1888 10: 1890 11: 1887 12: 1890 13: 1994 14: 2049 15: 1884 16: 1897 
Graphics:  Device-1: NVIDIA GP107 [GeForce GTX 1050 Ti] driver: nvidia v: 460.32.03 
           Display: server: X.org 1.20.9 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa tty: 156x16 
           Message: Advanced graphics data unavailable in console. Try -G --display 
Audio:     Device-1: NVIDIA GP107GL High Definition Audio driver: snd_hda_intel 
           Device-2: Advanced Micro Devices [AMD] Family 17h HD Audio driver: snd_hda_intel 
           Device-3: Sunplus Innovation Live Camera type: USB driver: snd-usb-audio,uvcvideo 
           Device-4: Logitech Logitech USB Headset type: USB driver: hid-generic,snd-usb-audio,usbhid 
           Sound Server: ALSA v: k5.8.0-44-generic 
Network:   Device-1: Intel Dual Band Wireless-AC 3168NGW [Stone Peak] driver: iwlwifi 
           IF: wlp30s0 state: up mac: 94:b8:6d:ce:67:60 
           Device-2: Intel I211 Gigabit Network driver: igb 
           IF: enp31s0 state: down mac: 70:85:c2:84:c6:f7 
Drives:    Local Storage: total: 3.22 TiB used: 1.89 TiB (58.6%) 
           ID-1: /dev/nvme0n1 vendor: Intel model: SSDPEKNW010T8 size: 953.87 GiB 
           ID-2: /dev/sda vendor: Seagate model: ST2000DM001-1CH164 size: 1.82 TiB 
           ID-3: /dev/sdb vendor: SK Hynix model: HFS512G39TND-N210A size: 476.94 GiB 
Partition: ID-1: / size: 937.40 GiB used: 26.69 GiB (2.8%) fs: ext4 dev: /dev/nvme0n1p3 
Swap:      ID-1: swap-1 type: file size: 2.00 GiB used: 0 KiB (0.0%) file: /swapfile 
Sensors:   System Temperatures: cpu: 38.4 C mobo: N/A gpu: nvidia temp: 32 C 
           Fan Speeds (RPM): N/A gpu: nvidia fan: 0% 
Info:      Processes: 392 Uptime: 19h 27m Memory: 31.35 GiB used: 5.84 GiB (18.6%) Init: systemd runlevel: 5 Shell: pwsh 
           inxi: 3.1.07 

Regression?

I do not know if the problem previously existed.

Other information

Unhandled exception. System.UnauthorizedAccessException: Access to the path is denied.
 ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
   at System.ConsolePal.Write(SafeFileHandle fd, Byte* bufPtr, Int32 count, Boolean mayChangeCursorPosition)
   at System.ConsolePal.Write(SafeFileHandle fd, Byte[] buffer, Int32 offset, Int32 count, Boolean mayChangeCursorPosition)
   at System.ConsolePal.UnixConsoleStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   at System.IO.StreamWriter.WriteLine(String value)
   at System.IO.TextWriter.SyncTextWriter.WriteLine(String value)
   at System.Console.WriteLine(String value)
   at FizzBuzz.Program.Main(String[] _) in /media/ninja/Programs/GitHub/FizzBuzz/src/CSharp/Program.cs:line 19
ghost commented 3 years ago

Tagging subscribers to this area: See info in area-owners.md if you want to be subscribed.

Issue Details
When writing to the Console on Ubuntu 20.04 from the latest Dotnet Core 5.0 SDK Snap Package, `System.UnauthorizedAccessException: Access to the path is denied.` is thrown. You can find affected code at [sharpninja/FizzBuzz](https://github.com/sharpninja/FizzBuzz) (look in any of the Dotnet projects under `src`) and [compiled binaries](https://github.com/sharpninja/FizzBuzz/blob/478c87754f42290f2033cb69dc677c3e95b0ac02/src/CSharp.tar.gz). ### Configuration .Net SDK 5.0.103 ``` > lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.10 Release: 20.10 Codename: groovy > inxi -F System: Host: ##### Kernel: 5.8.0-44-generic x86_64 bits: 64 Console: tty 9 Distro: Ubuntu 20.10 (Groovy Gorilla) Machine: Type: Desktop Mobo: ASRock model: X470 Master SLI/ac serial: UEFI: American Megatrends v: P1.50 date: 11/06/2018 CPU: Info: 8-Core model: AMD Ryzen 7 2700X bits: 64 type: MT MCP L2 cache: 4096 KiB Speed: 1886 MHz min/max: 2200/3700 MHz Core speeds (MHz): 1: 1885 2: 2017 3: 2195 4: 2151 5: 1888 6: 1891 7: 1886 8: 1888 9: 1888 10: 1890 11: 1887 12: 1890 13: 1994 14: 2049 15: 1884 16: 1897 Graphics: Device-1: NVIDIA GP107 [GeForce GTX 1050 Ti] driver: nvidia v: 460.32.03 Display: server: X.org 1.20.9 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa tty: 156x16 Message: Advanced graphics data unavailable in console. Try -G --display Audio: Device-1: NVIDIA GP107GL High Definition Audio driver: snd_hda_intel Device-2: Advanced Micro Devices [AMD] Family 17h HD Audio driver: snd_hda_intel Device-3: Sunplus Innovation Live Camera type: USB driver: snd-usb-audio,uvcvideo Device-4: Logitech Logitech USB Headset type: USB driver: hid-generic,snd-usb-audio,usbhid Sound Server: ALSA v: k5.8.0-44-generic Network: Device-1: Intel Dual Band Wireless-AC 3168NGW [Stone Peak] driver: iwlwifi IF: wlp30s0 state: up mac: 94:b8:6d:ce:67:60 Device-2: Intel I211 Gigabit Network driver: igb IF: enp31s0 state: down mac: 70:85:c2:84:c6:f7 Drives: Local Storage: total: 3.22 TiB used: 1.89 TiB (58.6%) ID-1: /dev/nvme0n1 vendor: Intel model: SSDPEKNW010T8 size: 953.87 GiB ID-2: /dev/sda vendor: Seagate model: ST2000DM001-1CH164 size: 1.82 TiB ID-3: /dev/sdb vendor: SK Hynix model: HFS512G39TND-N210A size: 476.94 GiB Partition: ID-1: / size: 937.40 GiB used: 26.69 GiB (2.8%) fs: ext4 dev: /dev/nvme0n1p3 Swap: ID-1: swap-1 type: file size: 2.00 GiB used: 0 KiB (0.0%) file: /swapfile Sensors: System Temperatures: cpu: 38.4 C mobo: N/A gpu: nvidia temp: 32 C Fan Speeds (RPM): N/A gpu: nvidia fan: 0% Info: Processes: 392 Uptime: 19h 27m Memory: 31.35 GiB used: 5.84 GiB (18.6%) Init: systemd runlevel: 5 Shell: pwsh inxi: 3.1.07 ``` ### Regression? I do not know if the problem previously existed. ### Other information ``` Unhandled exception. System.UnauthorizedAccessException: Access to the path is denied. ---> System.IO.IOException: Permission denied --- End of inner exception stack trace --- at System.ConsolePal.Write(SafeFileHandle fd, Byte* bufPtr, Int32 count, Boolean mayChangeCursorPosition) at System.ConsolePal.Write(SafeFileHandle fd, Byte[] buffer, Int32 offset, Int32 count, Boolean mayChangeCursorPosition) at System.ConsolePal.UnixConsoleStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) at System.IO.StreamWriter.WriteLine(String value) at System.IO.TextWriter.SyncTextWriter.WriteLine(String value) at System.Console.WriteLine(String value) at FizzBuzz.Program.Main(String[] _) in /media/ninja/Programs/GitHub/FizzBuzz/src/CSharp/Program.cs:line 19 ```
Author: sharpninja
Assignees: -
Labels: `area-System.Console`, `area-System.IO`, `untriaged`
Milestone: -
jozkee commented 3 years ago

@sharpninja are you able to repro this consistently? Could you please verify installing .NET with a method other than snap? How do you start the process, are you redirecting the standard output?

sharpninja commented 3 years ago

Yes, it happens every time. That GitHub repo has five different .Net Projects (3x C#, 1x F# and 1x VB.Net) that exhibit the same behavior.

Edit: I will try to install via the install_dotnet script tonight and test that way.

adamsitnik commented 3 years ago

Hi @sharpninja

I've taken a look at the example that you have provided and I can't find a reason why it would be throwing.

May I ask how exactly do you run the app? Which terminal are you using? How is the dotnet process being started? Is the input reditected? Is there a script that I could run to repro it?

Thanks, Adam

adamsitnik commented 12 months ago

May I ask how exactly do you run the app? Which terminal are you using? How is the dotnet process being started? Is the input reditected? Is there a script that I could run to repro it?

No response for 2 years, closing.