polybar / polybar

A fast and easy-to-use status bar

Home Page:https://polybar.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: polybar freezes on i3 when running certain modules

lucasreis1 opened this issue · comments

Checklist

  • I have read the appropriate section in the contributing guidelines
  • I believe this issue is a problem with polybar itself and not a misconfiguration on my part
  • I have searched for other open and closed issues that may have already reported this problem
  • I have checked the known issues page for this problem.
  • I have followed the debugging guide to narrow down the problem to a minimal config.

Steps to reproduce

  1. polybar -r simple
  2. wait (could be a couple minutes, could be some hours)
  3. complete freeze, polybar hangs. ps shows zombie child processes

Minimal config

[bar/simple]
# this will change depending on the monitor
monitor = ${env:PRIMARY_MONITOR:DP-4}
width = 100%

height = 22pt

background = ${colors.background}
foreground = ${colors.foreground}


padding-left = 0
padding-right = 1

module-margin = 1

;separator = |
separator-foreground = ${colors.disabled}

font-0 = "JetBrainsMono Nerd Font:style=Normal:size=10;3"
font-1 = "JetBrainsMono Nerd Font:style=Medium:size=10;3"
font-2 = "JetBrainsMono Nerd Font:style=Bold:size=11;3"
font-3 = "JetBrainsMono Nerd Font:style=Italic:size=10;3"
font-4 = "JetBrainsMono Nerd Font:style=Medium Italic:size=10;3"
font-5 = "JetBrainsMono Nerd Font:size=10;5"

font-6 = "feather:size=14;3.5"
;
font-7 = "Material Icons:size=14;3"
font-8 = "Material Icons Outlined:size=12;4"
font-9 = "Material Icons Round:size=14;4"
font-10 = "Material Icons Sharp:size=12;4"
font-11 = "Material Icons TwoTone:size=12;4"
# for increasing font size of some icons
font-12 = "Material Icons Round:size=15;4"
font-13 = "Weather Icons:size=11;1"
font-14 = "Font Awesome 6 Brands, Font Awesome 6 Brands Regular;size=17;1"
font-15 = "feather:size=11;3.5"

# make the border rounded and transparent on the outside
radius = 6
border-size = 4pt
# transparent round border
border-color = #00000000
line-size = 4pt
border-bottom-size = 2
border-bottom-color = ${colors.primary}
enable-ipc = true

modules-left = i3
modules-right = battery-dualshock4-icon battery-dualshock4 sep eth sep date time

cursor-click = pointer
cursor-scroll = ns-resize

[module/battery-dualshock4-icon]
type= custom/ipc
hook-0 = echo ""
hook-1 = echo "  %{T16}%{T-}"
label-font = 10
format-foreground = ${colors.primary}
initial = 0

[module/battery-dualshock4]
type= custom/script
exec = ~/.config/polybar/scripts/info-dualshock4.sh &
interval = 10

Polybar log

polybar|notice:  Parsing config file: /home/lucas/.config/polybar/config.ini
polybar|notice:  Parsing config file: /home/lucas/.config/polybar/config.ini
polybar|notice:  Listening for IPC messages (PID: 2280152)
polybar|notice:  Listening for IPC messages (PID: 2280153)
polybar|notice:  Loading module 'i3' of type 'internal/i3'
polybar|notice:  Loading module 'i3' of type 'internal/i3'
polybar|notice:  Loading module 'powermenu-info' of type 'custom/ipc'
polybar|notice:  Loading module 'powermenu-info' of type 'custom/ipc'
polybar|notice:  Loading module 'ncspot-playpausestop' of type 'custom/ipc'
polybar|notice:  Loading module 'ncspot-playpausestop' of type 'custom/ipc'
polybar|notice:  Loading module 'ncspot' of type 'custom/script'
polybar|notice:  Loading module 'ncspot' of type 'custom/script'
polybar|notice:  Loading module 'battery-dualshock4-icon' of type 'custom/ipc'
polybar|notice:  Loading module 'battery-dualshock4-icon' of type 'custom/ipc'
polybar|notice:  Loading module 'battery-dualshock4' of type 'custom/script'
polybar|notice:  Loading module 'battery-dualshock4' of type 'custom/script'
polybar|notice:  Loading module 'sep' of type 'custom/text'
polybar|notice:  Loading module 'sep' of type 'custom/text'
polybar|warn:  The config parameter `module/sep.content` is deprecated, use `module/sep.format` instead.
polybar|notice:  Loading module 'eth' of type 'internal/network'
polybar|warn:  The config parameter `module/sep.content` is deprecated, use `module/sep.format` instead.
polybar|notice:  Loading module 'eth' of type 'internal/network'
polybar|notice:  module/eth: Discovered wired interface enp7s0
polybar|notice:  module/eth: Discovered wired interface enp7s0
polybar|notice:  Loading module 'sep' of type 'custom/text'
polybar|notice:  Loading module 'sep' of type 'custom/text'
polybar|warn:  The config parameter `module/sep.content` is deprecated, use `module/sep.format` instead.
polybar|notice:  Loading module 'date' of type 'internal/date'
polybar|warn:  The config parameter `module/sep.content` is deprecated, use `module/sep.format` instead.
polybar|notice:  Loading module 'date' of type 'internal/date'
polybar|notice:  Loading module 'time' of type 'internal/date'
polybar|notice:  Loading module 'time' of type 'internal/date'
polybar|notice:  Loaded 11 modules
polybar|notice:  Loaded 11 modules
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Normal:size=10" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Regular Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Normal:size=10" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Regular Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Medium:size=10" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Medium Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Medium:size=10" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Medium Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Bold:size=11" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Bold Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Bold:size=11" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Bold Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Italic:size=10" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Italic Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Italic:size=10" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Italic Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Medium Italic:size=10" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Medium Italic Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:style=Medium Italic:size=10" (name=JetBrainsMono Nerd Font, offset=3, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Medium Italic Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:size=10" (name=JetBrainsMono Nerd Font, offset=5, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Regular Nerd Font Complete.ttf)
polybar|notice:  Loaded font "JetBrainsMono Nerd Font:size=10" (name=JetBrainsMono Nerd Font, offset=5, file=/home/lucas/.fonts/JetBrains/JetBrains Mono Regular Nerd Font Complete.ttf)
polybar|notice:  Loaded font "feather:size=14" (name=feather, offset=3, file=/home/lucas/.local/share/fonts/Icomoon-Feather.ttf)
polybar|notice:  Loaded font "feather:size=14" (name=feather, offset=3, file=/home/lucas/.local/share/fonts/Icomoon-Feather.ttf)
polybar|notice:  Loaded font "Material Icons:size=14" (name=Material Icons, offset=3, file=/usr/share/fonts/TTF/MaterialIcons-Regular.ttf)
polybar|notice:  Loaded font "Material Icons:size=14" (name=Material Icons, offset=3, file=/usr/share/fonts/TTF/MaterialIcons-Regular.ttf)
polybar|notice:  Loaded font "Material Icons Outlined:size=12" (name=Material Icons Outlined, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsOutlined-Regular.otf)
polybar|notice:  Loaded font "Material Icons Outlined:size=12" (name=Material Icons Outlined, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsOutlined-Regular.otf)
polybar|notice:  Loaded font "Material Icons Round:size=14" (name=Material Icons Round, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsRound-Regular.otf)
polybar|notice:  Loaded font "Material Icons Round:size=14" (name=Material Icons Round, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsRound-Regular.otf)
polybar|notice:  Loaded font "Material Icons Sharp:size=12" (name=Material Icons Sharp, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsSharp-Regular.otf)
polybar|notice:  Loaded font "Material Icons Sharp:size=12" (name=Material Icons Sharp, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsSharp-Regular.otf)
polybar|notice:  Loaded font "Material Icons TwoTone:size=12" (name=Material Icons Two Tone, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsTwoTone-Regular.otf)
polybar|notice:  Loaded font "Material Icons TwoTone:size=12" (name=Material Icons Two Tone, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsTwoTone-Regular.otf)
polybar|notice:  Loaded font "Material Icons Round:size=15" (name=Material Icons Round, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsRound-Regular.otf)
polybar|notice:  Loaded font "Material Icons Round:size=15" (name=Material Icons Round, offset=4, file=/home/lucas/.fonts/MaterialIcons/MaterialIconsRound-Regular.otf)
polybar|notice:  Loaded font "Weather Icons:size=11" (name=Weather Icons, offset=1, file=/home/lucas/.fonts/weather-icons/weathericons-regular-webfont.ttf)
polybar|notice:  Loaded font "Weather Icons:size=11" (name=Weather Icons, offset=1, file=/home/lucas/.fonts/weather-icons/weathericons-regular-webfont.ttf)
polybar|notice:  Loaded font "Font Awesome 6 Brands, Font Awesome 6 Brands Regular;size=17" (name=Font Awesome 6 Brands, offset=1, file=/usr/share/fonts/TTF/fa-brands-400.ttf)
polybar|notice:  Loaded font "Font Awesome 6 Brands, Font Awesome 6 Brands Regular;size=17" (name=Font Awesome 6 Brands, offset=1, file=/usr/share/fonts/TTF/fa-brands-400.ttf)
polybar|notice:  Loaded font "feather:size=11" (name=feather, offset=3, file=/home/lucas/.local/share/fonts/Icomoon-Feather.ttf)
polybar|notice:  Loaded font "feather:size=11" (name=feather, offset=3, file=/home/lucas/.local/share/fonts/Icomoon-Feather.ttf)

Expected behavior

Polybar should work as expected, updating and being responsive

Actual behavior

Total freeze, modules do not respond anymore, the bar is virtually hanging forever. The only solution is to kill the bar and start it again

Window Manager and Version

i3 version 4.22 (2023-01-02)

Linux Distribution

Arch kernel 6.5.5-arch1-1

Polybar version

polybar 3.6.3-211-g53661e99

Features: +alsa +curl +i3 +mpd +network(libnl) +pulseaudio +xkeyboard

X extensions: +randr (+monitors) +composite +xkb +xrm +xcursor

Build type: Release
Compiler: /usr/bin/c++
Compiler flags: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -O3 -DNDEBUG -Wall -Wextra -Wpedantic -Wdeprecated-copy-dtor -Wsuggest-override
Linker flags: -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -Wall -Wextra -Wpedantic -Wdeprecated-copy-dtor -Wsuggest-override  -Wall -Wextra -Wpedantic -Wdeprecated-copy-dtor -Wsuggest-override

Additional Context / Screenshots

If it is of any help, I'm starting polybar from i3 using a simple script:

#!/bin/bash 
SCREEN_INFO=$(xrandr | grep "^DP-2" | cut -d' ' -f3 | cut -d'+' -f 1)

pkill polybar

# bars in the default monitor
polybar --reload simple & 

# we are not running a mirrored screen on secondary monitor
if [ "$SCREEN_INFO" == "1920x1080" ]; then
  # bars in the second monitor
  PRIMARY_MONITOR=DP-2 polybar --reload simple & 
fi

Per testing, the responsible module(s) is/are battery-dualshock4-icon and battery-dualshock4

Here's the script called by the module:

#!/bin/sh

PARENT_BAR="simple"
PARENT_BAR_PID=$(pgrep -a "polybar" | grep "$PARENT_BAR" | cut -d" " -f1)
DS_DIR='/sys/class/power_supply/ps-controller-battery-'

# lookup the status of the controller to see if its charging
check_status() {
  CHARGE_STATE=$(cat "$DS_DIR"*/status 2>/dev/null)
  if [ "$CHARGE_STATE" == "Charging" ];
  then
    update_hooks 1
  else
    update_hooks 0
  fi
}

# hook 0 -> disconnected/full
# hook 1 -> charging
update_hooks(){
  # lookup only for the parent bars
  for PID in $PARENT_BAR_PID; do
    polybar-msg -p $PID action "#battery-dualshock4-icon.hook.$1" &>/dev/null
  done
}

# checks if ds4 is connected and charging
check_status
BATTERY_PERC=$(cat "$DS_DIR"*/capacity 2>/dev/null)
if [ $? -eq 0 ]; then
  echo $BATTERY_PERC%
else
  echo "not connected"
fi

Also, here's ps --forest output for good measure:

610875 pts/16   S      0:00 /bin/bash /home/lucas/.config/polybar/scripts/polybar-spotify/get_spotify_status.sh
2463906 pts/16   S      0:00 /bin/sh /home/lucas/.config/polybar/scripts/info-dualshock4.sh
2463917 pts/16   Sl     0:00  \_ polybar-msg -p 2280152 action #battery-dualshock4-icon.hook.0
2463900 pts/16   S      0:00 /bin/sh /home/lucas/.config/polybar/scripts/info-dualshock4.sh
2463913 pts/16   Sl     0:00  \_ polybar-msg -p 2280152 action #battery-dualshock4-icon.hook.0
2463886 pts/16   S      0:00 /bin/bash /home/lucas/.config/polybar/scripts/polybar-spotify/get_spotify_status.sh
2463897 pts/16   Sl     0:00  \_ polybar-msg -p 2280152 action ncspot-playpausestop hook 1
2463872 pts/16   S      0:00 /bin/bash /home/lucas/.config/polybar/scripts/polybar-spotify/get_spotify_status.sh
2463883 pts/16   Sl     0:00  \_ polybar-msg -p 2280152 action ncspot-playpausestop hook 1
2463855 pts/16   S      0:00 /bin/bash /home/lucas/.config/polybar/scripts/polybar-spotify/get_spotify_status.sh
2463869 pts/16   Sl     0:00  \_ polybar-msg -p 2280152 action ncspot-playpausestop hook 1
2280153 pts/16   Rl     0:29 polybar --reload simple
2280152 pts/16   Sl     0:20 polybar --reload simple
2463851 pts/16   Z      0:00  \_ [sh] <defunct>
2610874 pts/16   Z      0:00  \_ [sh] <defunct>

Thanks for the detailed report. There is nothing obvious sticking out right now. I'll need to reproduce this myself.

Just a few followup questions for that:

  • How did you determine that the two modules are responsible? Did you run the bar with only the two modules and they still froze?
  • If yes, how did you detect the freeze? With only the two modules, there are no clickable areas.
  • The ps --forest output is when you run polybar on two monitors, right?

How did you determine that the two modules are responsible? Did you run the bar with only the two modules and they still froze?

I've been on-an-off removing modules and testing the bars without them, and it seems the issues stop when these are removed. I haven't made any tests with only these modules isolated yet since reproducing it is really random and it's terrible to have no functional bars while I wait for crashes. If it helps, I have a music script that used to cause the same issue, so they both seem to trigger it. It was just easier to spot with the dualshock modules.

I can try isolating the bar and running some tests, but I'll probably still keep the i3 modules to make it easier to detect the freeze.

If yes, how did you detect the freeze? With only the two modules, there are no clickable areas.

I keep at least the i3 module so I have an easy way to detect the issue when workspaces are not updating any more

The ps --forest output is when you run polybar on two monitors, right?

Yeah, I'm running two bars for each monitor, one on top and one on the bottom of the screen.

Quick update: I was able to replicate it more consistently with the following modules:

modules-left = i3 
modules-center = ncspot-playpausestop ncspot
modules-right = battery-dualshock4-icon battery-dualshock4 

Here's how the remaining modules are structured:

[module/ncspot-playpausestop]
type = custom/ipc
hook-0 = echo ""
hook-1 = echo ""
hook-2 = echo ""
label-font = 10
format-foreground = ${colors.primary}
initial = 2

[module/ncspot]
type = custom/script
tail = true
interval = 1

format = <label>
exec = ~/.config/polybar/scripts/polybar-spotify/get_spotify_status.sh &
click-left = i3-msg '[instance="music"] scratchpad show'

And get_spotify_status.sh:

#!/bin/bash

# The name of polybar bar which houses the main spotify module and the control modules.
PARENT_BAR="simple"
PARENT_BAR_PID=$(pgrep -a "polybar" | grep "$PARENT_BAR" | cut -d" " -f1)

# Set the source audio player here.
# Players supporting the MPRIS spec are supported.
# Examples: spotify, vlc, chrome, mpv and others.
# Use `playerctld` to always detect the latest player.
# See more here: https://github.com/altdesktop/playerctl/#selecting-players-to-control
PLAYER="ncspot"
MODULE="ncspot-playpausestop"

# Format of the information displayed
# Eg. {{ artist }} - {{ album }} - {{ title }}
# See more attributes here: https://github.com/altdesktop/playerctl/#printing-properties-and-metadata
FORMAT="{{ title }} - {{ artist }}"

# Sends $2 as message to all polybar PIDs that are part of $1
update_hooks() {
  #polybar-msg action "#$MODULE" $2 1>/dev/null 2>&1
  while IFS= read -r id
  do
    polybar-msg -p "$id" action $MODULE hook $2 &>/dev/null 
  done < <(echo "$1")
}

PLAYERCTL_STATUS=$(playerctl --player=$PLAYER status 2>/dev/null)
EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
    STATUS=$PLAYERCTL_STATUS
else
    STATUS="No player is running"
fi

if [ "$1" == "--status" ]; then
    echo "$STATUS"
else
    if [ "$STATUS" = "Stopped" ]; then
        update_hooks "$PARENT_BAR_PID" 2
        echo "No music is playing"
    elif [ "$STATUS" = "Paused"  ]; then
        update_hooks "$PARENT_BAR_PID" 1
        playerctl --player=$PLAYER metadata --format "$FORMAT"
    elif [ "$STATUS" = "No player is running"  ]; then
        echo "$STATUS"
    else
        update_hooks "$PARENT_BAR_PID" 0
        playerctl --player=$PLAYER metadata --format "$FORMAT"
    fi
fi

I've also been running my main bar together with this one, which contains a ton of modules, including the ncspot music modules, but does not include the dualshock modules. This bar has not crashed on me for as long as I remember starting these experiments.

I still have no idea what causes the issue as freezes are pretty random in my system, but they often occur hourly/semi-hourly. If there's any more missing context that could be of help, please let me know!

Just a quick update as I'm still dealing with the issues at hand. The presence of modules such as ncspot and dualshock4-battery seems to be an integral part of the issue. With any of these included, the crashes are bound to happen. I realized that it happens more frequently when Steam is open, and killing polybar and restarting after a freeze immediately sends me to the workspace that Steam is on. In fact, this issue seem more frequent ever since steam updated their UI.

Also, I've run strace to see if I could get more info, but found nothing that could be of help (when the bar crashes, some syscall outputs are just left dangling). Really wish I could help more, but it is pretty hard to reproduce this on demand.