Skip to content

Bug: race condition when triggering multiple IPC hooks simultaneously #2504

@chasecaleb

Description

@chasecaleb

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.

Describe the bug

In certain circumstances, sending multiple hook messages in a row will consistently result in a race condition where only some of the messages are received. Observations:

  • This occurs whether through polybar-msg or by writing directly to the FIFO pipe file (/tmp/polybar_mqueue.<pid>).
  • This occurs consistently in the reproduction provided below. This isn't a once-in-a-blue-moon type of race condition.
  • This appears to be related to how quickly the hook commands are sent vs how quickly the hook commands complete, because I can reproduce it multiple ways by varying:
    1. How many different hook messages are sent simultaneously
    2. How long the hook commands take (via sleep)

Expected behavior:
All hook messages should be received and handled

Actual behavior:
Some of the last hook messages disappear into a black hole

Was it working before?

  • Did you also experience this bug in an earlier version of polybar (yes/no/don't know)? Don't know, first time using polybar
  • If no, what was the last version where this worked correctly?

To Reproduce

Config:

[bar/panel]
enable-ipc = true
modules-left = test-a test-b test-c
separator = " | "

[module/test-a]
type = custom/ipc
hook-0 = bash -c 'sleep 0.1 && uuidgen | head -c 8'
initial = 1

[module/test-b]
type = custom/ipc
hook-0 = bash -c 'sleep 0.1 && uuidgen | head -c 8'
initial = 1

[module/test-c]
type = custom/ipc
hook-0 = bash -c 'sleep 0.1 && uuidgen | head -c 8'
initial = 1

Steps:

  1. Start polybar: polybar panel --config=/tmp/polybar-demo.conf &
  2. Trigger bug: polybar-msg hook test-a 1 && polybar-msg hook test-b 1 && polybar-msg hook test-c 1
    • Watch the UUIDs in the bar, you'll notice that only the first one changes
  3. Add delays to avoid bug: polybar-msg hook test-a 1 && sleep 0.2 && polybar-msg hook test-b 1 && sleep 0.2 && polybar-msg hook test-c 1
    • This time you'll notice that all three UUIDs change as expected

Polybar Log

From doing only steps 1 and 2 in the repo above:

polybar|notice:  Parsing config file: /tmp/polybar-demo.conf
polybar|trace: config_parser: Parsing /tmp/polybar-demo.conf
polybar|info:  Created ipc channel at: /tmp/polybar_mqueue.9390
polybar|info:  Loaded monitor Virtual1 (3840x2160+0+0)
polybar|info:  Bar geometry: 3840x24+0+0; Borders: 0,0,0,0
polybar|trace: bar: Attach X event sink
polybar|trace: bar: Attach signal receiver
polybar|trace: controller: Install signal handler
polybar|trace: controller: Setup user-defined modules
polybar|info:  Starting application
polybar|trace: controller: Main thread id = 1
polybar|info:  Starting module/test-a
polybar|info:  Starting module/test-b
polybar|trace: module/test-a: Thread id = 2
polybar|info:  Starting module/test-c
polybar|trace: module/test-b: Thread id = 3
polybar|info:  Entering event loop (thread-id=1)
polybar|trace: module/test-c: Thread id = 4
polybar|info:  Eventqueue worker (thread-id=5)
polybar|trace: bar: Create renderer
polybar|trace: renderer: Get TrueColor visual
polybar|trace: renderer: Allocate colormap
polybar|trace: renderer: Allocate output window
polybar|trace: renderer: Allocate window pixmaps
polybar|trace: renderer: Allocate graphic contexts
polybar|trace: renderer: Allocate alignment blocks
polybar|trace: renderer: Allocate cairo components
polybar|trace: renderer: Load fonts
polybar|info:  Configured DPI = 96x96
polybar|warn:  No fonts specified, using fallback font "fixed"
polybar|notice:  Loaded font "fixed" (name=Verdana, offset=0, file=/usr/share/fonts/TTF/Verdana.TTF)
polybar|info:  Bar window: 0x3000001
polybar|trace: bar: Reconfigure window
polybar|trace: bar: Set window WM_NAME
polybar|trace: bar: Set window _NET_WM_WINDOW_TYPE
polybar|trace: bar: Set window _NET_WM_STATE
polybar|trace: bar: Set window _NET_WM_DESKTOP
polybar|trace: bar: Set window _NET_WM_PID
polybar|trace: bar: Map window
polybar|trace: bar: Draw empty bar
polybar|trace: bar: Setup tray manager
polybar|info:  Disabling tray manager (reason: missing `tray-position`)
polybar|info:  module/test-a: Rebuilding cache
polybar|info:  module/test-b: Rebuilding cache
polybar|info:  module/test-c: Rebuilding cache
polybar|trace: bar: Force update
polybar|info:  Redrawing bar window
polybar|trace: renderer: flush(1 geom=266x24+0+0, falloff=0)
polybar|trace: bar: Received expose event
polybar|info:  Receiving ipc message
polybar|info:  module/test-a: Found matching hook (module/test-a1)
polybar|info:  Receiving ipc message
polybar|info:  module/test-a: Rebuilding cache
polybar|info:  Redrawing bar window
polybar|trace: renderer: flush(1 geom=278x24+0+0, falloff=0)
polybar|notice:  Termination signal received, shutting down...
polybar|trace: controller: Uninstall sighandler
polybar|trace: controller: Detach signal receiver
polybar|trace: controller: Stop modules
polybar|info:  module/test-a: Stopping
polybar|trace: module/test-a: Release sleep lock
polybar|info:  Deconstruction of module/test-a took 0 ms.
polybar|info:  module/test-b: Stopping
polybar|trace: module/test-b: Release sleep lock
polybar|info:  Deconstruction of module/test-b took 0 ms.
polybar|info:  module/test-c: Stopping
polybar|trace: module/test-c: Release sleep lock
polybar|info:  Deconstruction of module/test-c took 0 ms.
polybar|trace: controller: Joining threads
polybar|trace: module/test-a: Deconstructing
polybar|trace: module/test-b: Deconstructing
polybar|trace: module/test-c: Deconstructing
polybar|trace: ipc: Removing file handle
polybar|info:  Waiting for spawned processes to end
polybar|info:  Reached end of application...

Notice this section in particular, showing only one of the three messages was handled:

polybar|trace: bar: Received expose event
polybar|info:  Receiving ipc message
polybar|info:  module/test-a: Found matching hook (module/test-a1)
polybar|info:  Receiving ipc message
polybar|info:  module/test-a: Rebuilding cache
polybar|info:  Redrawing bar window

Environment:

  • WM: EXWM, although I don't think this is relevant
  • Distro: Arch Linux
  • Output of polybar -vvv:
> polybar -vvv
polybar 3.5.6

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 -Wall -Wextra -Wpedantic -O3 -DNDEBUG
Linker flags: -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now 

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions