aristocratos / btop

A monitor of resources
Apache License 2.0
21.22k stars 649 forks source link

[BUG] Exception while unlocking the Config lock #697

Open UtsavBalar1231 opened 11 months ago

UtsavBalar1231 commented 11 months ago

Describe the bug

After running btop and try to switch between different presets, there seems to be a crash during Config::unlock() which ends up with error key not found. Happens everytime on my PC while switching between different presets.

To Reproduce

Expected behavior

Screenshots https://github.com/aristocratos/btop/assets/32286881/c56446f3-911c-4c27-bc6f-a952dd696236

Info (please complete the following information):

Btop version: v1.3.0 (AUR as well as self-compiled) LLVM version: 16.0.6, LTO enabled

System information

OS: Arch Linux x86_64
Host: Nitro AN515-52 (V1.28)
Kernel: 6.6.8-arch1-1
Uptime: 58 mins
Packages: 1115 (pacman)
Shell: zsh 5.9
Display (AUO61ED): 1920x1080 @ 60Hz *
Display (VG240Y M3): 1920x1080 @ 180Hz
WM: i3 (X11)
Theme: Gruvbox-Material-Dark-HIDPI [GTK2/3]
Icons: Gruvbox-Plus-Dark [GTK2/3]
Font: FiraCode Nerd Font weight=450 (15pt) [GTK2/3]
Cursor: Bibata-Modern-Ice
Terminal: kitty 0.31.0
Terminal Font: FiraCodeNF-Reg (16pt)
CPU: Intel(R) Core(TM) i5-8300H (8) @ 4.00 GHz
GPU 1: Intel UHD Graphics 630
GPU 2: NVIDIA GeForce GTX 1050 Mobile
Memory: 2.73 GiB / 7.60 GiB (36%)
Swap: 512.00 KiB / 7.97 GiB (0%)
Disk (/): 98.91 GiB / 225.33 GiB (44%) - ext4
Local IP (wlan0): 192.168.0.124/24 *
Battery: 100% [Full]
Locale: en_US.UTF-8

Additional context

Contents of ~/.config/btop/btop.log

2023/12/25 (11:18:30) | ===> btop++ v.1.3.0
2023/12/25 (11:18:30) | DEBUG: Starting in DEBUG mode!
2023/12/25 (11:18:30) | INFO: Logger set to DEBUG
2023/12/25 (11:18:30) | DEBUG: Using locale en_US.UTF-8
2023/12/25 (11:18:30) | INFO: Running on /dev/pts/2
2023/12/25 (11:18:30) | DEBUG: Shared::init() : Initialized.
2023/12/25 (11:18:30) | DEBUG: Loading theme file: /usr/share/btop/themes/gruvbox_material_dark.theme
2023/12/25 (11:18:31) | DEBUG: Writing new config file
2023/12/25 (11:18:31) | ERROR: Exception during Config::unlock() : key not found
2023/12/25 (11:18:31) | INFO: Quitting! Runtime: 00:00:01

GDB Backtrace

Not able to get any trace from any thread. Even after compiling as Debug build.

(gdb) r --debug
Starting program: /home/utsav/dev/btop/bin/btop --debug
Downloading separate debug info for system-supplied DSO at 0x7ffff7fc8000                                                                         
[Thread debugging using libthread_db enabled]                                                                                                     
Using host libthread_db library "/usr/lib/libthread_db.so.1".
ERROR: Exception during Config::unlock() : key not found
[Thread 0x7fffeffff6c0 (LWP 62561) exited]
[Inferior 1 (process 62522) exited with code 01]
(gdb) thread apply all bt
(gdb) 
rkowalsk commented 10 months ago

The crash doesn't always occur while going through the presets. To make it appear, you can press 5 to enable the GPU view and then go through the presets.

UtsavBalar1231 commented 10 months ago

Tried with GPU view as switching between presets, Same behavior as previous, it crashes arbitrarily.

btop.log

2024/01/10 (18:28:45) | ===> btop++ v.1.3.0
2024/01/10 (18:28:45) | WARNING: NVML: Failed to get maximum GPU power draw, defaulting to 225W: Not Supported
2024/01/10 (18:28:45) | WARNING: NVML: Failed to get GPU power usage: Not Supported
2024/01/10 (18:28:55) | ERROR: Exception during Config::unlock() : unordered_map::at

2024/01/10 (18:29:59) | ===> btop++ v.1.3.0
2024/01/10 (18:29:59) | WARNING: NVML: Failed to get maximum GPU power draw, defaulting to 225W: Not Supported
2024/01/10 (18:29:59) | WARNING: NVML: Failed to get GPU power usage: Not Supported
2024/01/10 (18:30:09) | ERROR: Exception during Config::unlock() : unordered_map::at

2024/01/10 (18:30:10) | ===> btop++ v.1.3.0
2024/01/10 (18:30:10) | WARNING: NVML: Failed to get maximum GPU power draw, defaulting to 225W: Not Supported
2024/01/10 (18:30:10) | WARNING: NVML: Failed to get GPU power usage: Not Supported
2024/01/10 (18:30:17) | ERROR: Exception during Config::unlock() : unordered_map::at

2024/01/10 (18:30:19) | ===> btop++ v.1.3.0
2024/01/10 (18:30:19) | WARNING: NVML: Failed to get maximum GPU power draw, defaulting to 225W: Not Supported
2024/01/10 (18:30:19) | WARNING: NVML: Failed to get GPU power usage: Not Supported
2024/01/10 (18:30:26) | ERROR: Exception during Config::unlock() : unordered_map::at

https://github.com/aristocratos/btop/assets/32286881/6b0944c0-06a2-480e-9b9f-af48886e02fa

sliva0 commented 9 months ago

I'm getting the same bug in the same circumstances (multiple p presses on startup).

btop --version:

btop version: 1.3.2

System information

OS: EndeavourOS Linux x86_64 
Host: ROG Zephyrus G16 GU603ZV 1.0 
Kernel: 6.7.4-zen1-1-zen 
Packages: 1288 (pacman), 18 (flatpak) 
Shell: bash 5.2.26  
CPU: 12th Gen Intel i7-12700H (20) @ 4.600GHz 
GPU: NVIDIA GeForce RTX 4060 Max-Q / Mobile 
GPU: Intel Alder Lake-P 
Memory: 15609MiB 

~/.config/btop/btop.log with DEBUG level:

2024/02/18 (19:45:18) | ===> btop++ v.1.3.2
2024/02/18 (19:45:18) | INFO: Logger set to DEBUG
2024/02/18 (19:45:18) | DEBUG: Using locale en_IE.UTF-8
2024/02/18 (19:45:18) | INFO: Running on /dev/pts/0
2024/02/18 (19:45:20) | WARNING: NVML: Failed to get maximum GPU power draw, defaulting to 225W: Not Supported
2024/02/18 (19:45:20) | INFO: Failed to load librocm_smi64.so, AMD GPUs will not be detected: librocm_smi64.so.6: cannot open shared object file: No such file or directory
2024/02/18 (19:45:20) | DEBUG: Shared::init() : Initialized.
2024/02/18 (19:45:27) | DEBUG: Writing new config file
2024/02/18 (19:45:27) | ERROR: Exception during Config::unlock() : unordered_map::at
2024/02/18 (19:45:27) | INFO: Quitting! Runtime: 00:00:09

btop package:

extra/btop   1.3.2-1
nico commented 7 months ago

Same here, crashes immediately when opening it and keeping p pressed:

$ btop --version
btop version: 1.3.0

$ time btop 
ERROR: Exception during Config::unlock() : unordered_map::at

real    0m0.946s
user    0m0.080s
sys     0m0.291s
reukiodo commented 7 months ago

I can also reproduce the issue in v1.3.0, and though my RX560 GPU doesn't even show up in the charts, it seems to be detected as GPU settings are shown in the options menu. OP has a 1050Ti, so the issue isn't strictly restricted to AMD or nVidia GPUs.

Uncomfy commented 5 months ago

The exception seems to be raised here: https://github.com/aristocratos/btop/blob/516979b2ae050a95a4bbd3928bc856e482a37097/src/btop_config.hpp#L110

Some keys are missing from strings variable which raises std::out_of_range when trying to use at() method with missing key.

For me the easiest way to reproduce this was to add a preset "cpu:0:default,gpu0:0:default" and to try to switch to it. This caused an update to "graph_symbol_gpu0" key, which was not present in the map, crashing btop. Simplest fix is to replace strings.at(name) = value; with strings[name] = value;, but I'm not sure this is a proper fix, maybe it breaks something else, or maybe the core issue is that not all values are added to the config, idk.

UPD: reproduction with a preset creates a slightly different error: ERROR: Exception in main loop -> Input::process("P") : _Map_base::at. But I think that Config::unlock one is caused by same issue, though you would need to replace all at()'s here to "fix" it.