btop icon indicating copy to clipboard operation
btop copied to clipboard

[BUG] segmentation fault after running btop over night

Open SeseMueller opened this issue 1 year ago • 12 comments

Describe the bug

I left a btop terminal window open overnight, trying to reproduce #316, but got a segmentation fault instead.

To Reproduce Start btop. Leave it on for a long time. Come back to a segementation fault.

Expected behavior

It shouldn't segfault

Screenshots

Bildschirm­foto 2023-02-04 um 10 38 09

Info (please complete the following information):

  • btop++ version: 1.2.13
  • Binary: native from fresh Homebrew install
  • (If compiled) Compiler and version:
  • Architecture: arm64
  • Platform: OsX
  • Terminal used: Warp
  • Font used: default

Additional context

contents of ~/.config/btop/btop.log (Logger set to DEBUG in options):

2023/02/03 (23:34:51) | ===> btop++ v.1.2.13 2023/02/03 (23:34:51) | WARNING: No UTF-8 locale detected! Some symbols might not display correctly. 2023/02/03 (23:35:02) | INFO: Logger set to INFO 2023/02/03 (23:35:03) | INFO: Logger set to DEBUG 2023/02/03 (23:35:03) | INFO: Logger set to DEBUG 2023/02/04 (00:28:23) | ERROR: failed getting network interfaces 2023/02/04 (01:02:28) | ERROR: Stall in Runner thread, restarting! 2023/02/04 (01:09:38) | ERROR: Stall in Runner thread, restarting! 2023/02/04 (01:44:13) | ERROR: Stall in Runner thread, restarting! 2023/02/04 (01:44:24) | ERROR: Stall in Runner thread, restarting! 2023/02/04 (01:46:07) | ERROR: Stall in Runner thread, restarting! 2023/02/04 (01:46:12) | ERROR: Stall in Runner thread, restarting! 2023/02/04 (02:38:36) | ERROR: Stall in Runner thread, restarting! 2023/02/04 (02:38:41) | ERROR: Stall in Runner thread, restarting! 2023/02/04 (02:38:46) | ERROR: Stall in Runner thread, restarting! 2023/02/04 (02:38:51) | ERROR: Stall in Runner thread, restarting!

(The segfault, as per the screenshot, happened at 02:38:46)

Edit: running it for a third time, I got another error:

btop(50807,0x16de9f000) malloc: double free for ptr 0x117008a00 zsh: abort btop --debug

So it seems that btop stops working after some time due to some error and displays either:

  • pointer being freed was not allocated
  • segmentation fault
  • double free for ptr

SeseMueller avatar Feb 04 '23 11:02 SeseMueller

There's a memory leak somewhere which I'm trying to detect; it increases by 3MiB on each second, at least on my system [GNU / Linux Debian].

stefanos82 avatar Feb 04 '23 17:02 stefanos82

@aristocratos can you explain this excerpt to me, please?

static InputThr& instance() {
	// intentional memory leak, to simplify shutdown process
	static InputThr* input = new InputThr();

	return *input;
}

It's from file btop_input.cpp if it helps.

valgrind detected it at line 128 and also

InputThr() : thr(run, this) {
}

from line 88.

Why would we want to intentionally leak memory?

Isn't there any other safer method to accomplish a shutdown process, in a more graceful way?

Please advice.

stefanos82 avatar Feb 04 '23 17:02 stefanos82

By the way, the leak takes place immediately with the following command, on my side: make DEBUG=true VERBOSE=true CXXFLAGS=-fsanitize=address,undefined,leak LDFLAGS=-fsanitize=address,undefined,leak ADDFLAGS="-fuse-ld=mold -ggdb3".

After it finishes the compilation, I filter for btop and within info, I can clearly see the memory leak taking place with every second that passes by; it increases by 3 MiB steadily.

stefanos82 avatar Feb 04 '23 18:02 stefanos82

@stefanos82

can you explain this excerpt to me, please?

See #227

By the way, the leak takes place immediately with the following command, on my side: make DEBUG=true VERBOSE=true CXXFLAGS=-fsanitize=address,undefined,leak LDFLAGS=-fsanitize=address,undefined,leak ADDFLAGS="-fuse-ld=mold -ggdb3".

Unless you are seeing this with sanitizers off not running in a debugger I would assume the sanitizing and debugger are creating the leak from trying to fix what looks like a leak but really isn't.

But I'm pretty sure this is unrelated to @SeseMueller's reported bug on MacOS arm64.

@SeseMueller What are your hardware specs?

aristocratos avatar Feb 21 '23 10:02 aristocratos

See #227

Got it :+1:

Unless you are seeing this with sanitizers off not running in a debugger I would assume the sanitizing and debugger are creating the leak from trying to fix what looks like a leak but really isn't.

Yeah, it probably is this scenario because indeed I cannot see this behavior otherwise.

stefanos82 avatar Feb 21 '23 10:02 stefanos82

@SeseMueller What are your hardware specs?

I've got a Macbook Air M1 with 16 Gb. It might not be related to my specs, but I have no other hardware to test it currently.

SeseMueller avatar Feb 21 '23 10:02 SeseMueller

I see the same bug / behavior on Ubuntu Server using btop 1.2.3

matt@lian:~/.config/btop$ neofetch
            .-/+oossssoo+/-.               matt@lian 
        `:+ssssssssssssssssss+:`           --------- 
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 22.04.2 LTS x86_64 
    .ossssssssssssssssssdMMMNysssso.       Kernel: 5.15.0-60-generic 
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Uptime: 2 days, 14 hours, 32 mins 
  +ssssssssshmydMMMMMMMNddddyssssssss+     Packages: 767 (dpkg), 5 (snap) 
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Shell: bash 5.1.16 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Resolution: 3440x1440 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Terminal: /dev/pts/0 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   CPU: Intel Xeon L5640 (12) @ 2.268GHz 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   GPU: AMD ATI Radeon RX 470/480/570/570X/580/580X/590 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Memory: 3537MiB / 11958MiB 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/                            
  +sssssssssdmydMMMMMMMMddddyssssssss+                             
   /ssssssssssshdmNNNNmyNMMMMhssssss/
    .ossssssssssssssssssdMMMNysssso.
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`
            .-/+oossssoo+/-.

023/03/01 (20:32:22) | ===> btop++ v.1.2.3 2023/03/01 (20:32:22) | ERROR: Stall in Runner thread, restarting!

ZMon3y avatar Mar 02 '23 13:03 ZMon3y

I have same bug after leaving it on for a long time on macos 12.6 (hw spec: mac m1 pro arm64/16gb ram/1tb ssd nvme). Btop version: 1.2.13 installed with brew package manager.

YHVHvx avatar Mar 12 '23 18:03 YHVHvx

Same issue here, usually segfaults on startup (though goes accompanied with eg. "terminate called without an active exception", will update once it happens again)

btop 1.2.13 neofetch:

[root@Rory@Rory-desktop ~]$ neofetch
                   -`                    root@Rory@Rory-desktop 
                  .o+`                   ---------------------- 
                 `ooo/                   OS: Arch Linux x86_64 
                `+oooo:                  Host: <redacted for length>
               `+oooooo:                 Kernel: 6.2.11-zen1-1-zen 
               -+oooooo+:                Uptime: 18 hours, 24 mins 
             `/:-:++oooo+:               Packages: 1844 (pacman), 70 (nix-user) 
            `/++++/+++++++:              Shell: bash 5.1.16 
           `/++++++++++++++:             Resolution: 3840x2160, 1920x1080 
          `/+++ooooooooooooo/`           WM: bspwm 
         ./ooosssso++osssssso+`          Theme: Adwaita [GTK2/3] 
        .oossssso-````/ossssss+`         Icons: Adwaita [GTK2/3] 
       -osssssso.      :ssssssso.        Terminal: kitty 
      :osssssss/        osssso+++.       Terminal Font: monospace 11.0 
     /ossssssss/        +ssssooo/-       CPU: AMD Ryzen 5 3600 (12) @ 3.600GHz 
   `/ossssso+/:-        -:/+osssso+-     GPU: NVIDIA GeForce RTX 2060 Rev. A 
  `+sso+:-`                 `.-/+oso:    GPU: NVIDIA GeForce GTX 760 OEM 
 `++:.                           `-/+/   Memory: 19998MiB / 40053MiB 
 .`                                 `/

TheArcaneBrony avatar May 16 '23 09:05 TheArcaneBrony

Same here btop 1.2.13 installed through brew macOS Montery 12.6.1 M1 Pro 32Gb Ram iTerm2 v3.4.19 zsh 5.8.1 (x86_64-apple-darwin21.0)

Runs for about a minute and then crashes

Screen Shot 2023-05-24 at 12 11 00 PM

jtowe1 avatar May 24 '23 16:05 jtowe1

Same issue, it occurs pretty much randomly for me, sometimes after just a few minutes but on other occasions it runs for hours. btop 1.12.13 installed through pacman

                   -`                    rex@archrex 
                  .o+`                   ----------- 
                 `ooo/                   OS: Arch Linux x86_64 
                `+oooo:                  Kernel: 6.3.4-arch2-1 
               `+oooooo:                 Uptime: 32 mins 
               -+oooooo+:                Packages: 1050 (pacman) 
             `/:-:++oooo+:               Shell: bash 5.1.16 
            `/++++/+++++++:              Resolution: 1920x1200, 2560x1440, 1920x1200 
           `/++++++++++++++:             DE: Plasma 5.27.5 
          `/+++ooooooooooooo/`           WM: KWin 
         ./ooosssso++osssssso+`          Theme: [Plasma], Breeze [GTK2/3] 
        .oossssso-````/ossssss+`         Icons: [Plasma], breeze-dark [GTK2/3] 
       -osssssso.      :ssssssso.        Terminal: kitty 
      :osssssss/        osssso+++.       CPU: AMD Ryzen 5 5600X (12) @ 3.700GHz 
     /ossssssss/        +ssssooo/-       GPU: NVIDIA GeForce RTX 3070 Ti 
   `/ossssso+/:-        -:/+osssso+-     Memory: 6951MiB / 23939MiB 
  `+sso+:-`                 `.-/+oso:
 `++:.                           `-/+/                           
 .`                                 `/                           

RexVizsla avatar May 30 '23 17:05 RexVizsla

Any update? I suspect this might be just the same issue with #765.

scr

For me the startup of btop just becomes unreasonably slow, and crashes in a minute. I thought it was macOS breaking something but a clean reboot did not fix it (see uptime below).

That being said, such things did not happen to me until I upgraded to macOS Sonoma 14.4. Could be their aggressive memory-violation strategy uncovering the issue. I'd love to help testing.

                     ..'          45gfg9@45gfg9-MacBook-Pro
                 ,xNMM.           -------------------------
               .OMMMMo            OS: macOS Sonoma 14.4.1 23E224 arm64
               lMM"               Host: MacBook Pro (16-inch, 2021)
     .;loddo:.  .olloddol;.       Kernel: 23.4.0
   cKMMMMMMMMMMNWMMMMMMMMMM0:     Uptime: 10 mins
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.     Packages: 345 (brew), 44 (brew-cask)
 XMMMMMMMMMMMMMMMMMMMMMMMX.       Shell: zsh 5.9
;MMMMMMMMMMMMMMMMMMMMMMMM:        Display (Color LCD): 3456x2234 @ 120Hz (as 1728x1117) [Built-in]
:MMMMMMMMMMMMMMMMMMMMMMMM:        DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX.       WM: Quartz Compositor
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.     WM Theme: Multicolor (Dark)
 'XMMMMMMMMMMMMMMMMMMMMMMMMMMk    Font: .AppleSystemUIFont [System], Helvetica [User]
  'XMMMMMMMMMMMMMMMMMMMMMMMMK.    Cursor: Fill - Black, Outline - White (32px)
    kMMMMMMMMMMMMMMMMMMMMMMd      Terminal: iTerm 3.4.23
     ;KMMMMMMMWXXWMMMMMMMk.       Terminal Font: SFMono-Regular (13pt)
       "cooc*"    "*coo'"         CPU: Apple M1 Max (10) @ 3.23 GHz
                                  GPU: Apple M1 Max (32) [Integrated]
                                  Memory: 14.80 GiB / 64.00 GiB (23%)
                                  Swap: Disabled
                                  Disk (/): 1.03 TiB / 1.81 TiB (57%) - apfs [Read-only]

45gfg9 avatar Apr 06 '24 07:04 45gfg9