mihirlad55 / polybar-dwm-module

A dwm module for polybar
MIT License
115 stars 15 forks source link

"module/dwm" stopped with reason: [dwmipcpp] Client with window id XXXXX not found #26

Open wongweilok opened 3 years ago

wongweilok commented 3 years ago

Describe the issue

"module/dwm" couldn't process and stopped due to some window id missing. This behaviour happens for android-studio dropdown menus as the menus spawn as "seperate window". These "seperate window" cannot be close with normal quit execution, it can only be close/remove by moving cursor away and thus causing this issue.

Expected behavior: module/dwm should be able to process the event changes and work as usual.

Actual behavior: module/dwm stopped working due to missing window id.

Was it working before?

To Reproduce

Issue might not related to config, but just in case: https://github.com/wongweilok/dotfiles/blob/master/.config/polybar/config_dwm

Step to reproduce:

  1. Open android-studio.
  2. Go to the menu and click on File --> New (Or any tab menu that have >= 2 level option), then move cursor away as figure below: screenshot-full-210324-113850
  3. Click on the editor or anywhere except the dropdown menus.
  4. Result: image

Polybar Log

Polybar outputs when the issue occur

notice: Parsing config file: /home/weilok/.config/polybar/config
notice: pulseaudio: using default sink alsa_output.pci-0000_00_09.2.analog-stereo
error: Disabling module "battery" (reason: No suitable way to get current capacity value)
notice: Loaded font "mono:pixelsize=9" (name=Inconsolata for Powerline, offset=1, file=/usr/share/fonts/Inconsolata for Powerline.otf)
notice: Loaded font "Inconsolata for Powerline:size=16" (name=Inconsolata for Powerline, offset=3, file=/usr/share/fonts/Inconsolata for Powerline.otf)
notice: Loaded font "Noto Color Emoji:scale=10:style=Regular" (name=Noto Color Emoji, offset=2, file=/usr/share/fonts/noto/NotoColorEmoji.ttf)
notice: Loaded font "Font Awesome 5 Free:style=Regular:pixelsize=8" (name=Font Awesome 5 Free, offset=1, file=/usr/share/fonts/TTF/fa-regular-400.ttf)
notice: Loaded font "Font Awesome 5 Free:style=Solid:pixelsize=8" (name=Font Awesome 5 Free, offset=1, file=/usr/share/fonts/TTF/fa-solid-900.ttf)
notice: Loaded font "Font Awesome 5 Brands:pixelsize=8" (name=Font Awesome 5 Brands, offset=1, file=/usr/share/fonts/TTF/fa-brands-400.ttf)
notice: Loaded font "Noto Sans CJK JP:size=8" (name=Noto Sans CJK JP, offset=1, file=/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc)
notice: Loaded font "Noto Sans CJK KR:size=8" (name=Noto Sans CJK KR, offset=1, file=/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc)
notice: Loaded font "Noto Sans CJK SC:size=8" (name=Noto Sans CJK SC, offset=1, file=/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc)
notice: Loaded font "Noto Sans CJK TC:size=8" (name=Noto Sans CJK TC, offset=1, file=/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc)
error: module/dwm: [dwmipcpp] Client with window id 18875311 not found
notice: Stopping 'module/dwm'...

*Note: The window id is vary.

Environment:

polybar 3.5.2-95-gbb94e184

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

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

Build type: Release
Compiler: /usr/bin/c++
Compiler flags: -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -Wall -Wextra -Wpedantic -O3 -DNDEBUG
Linker flags: -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now
wongweilok commented 3 years ago

Currently, android-studio is the only program I have issue with. I will try testing other different programs later.

wongweilok commented 3 years ago

I have tested and reproduced the same issue with using R in the terminal. Inside R, I created a plot as figure below.

screenshot-full-210324-133220

Executing quit command on the plot itself work as expected. However, executing quit command on the terminal (which was the parent client of the plot) cause the "module/dwm" to stopped working.

The same thing happened when opening an image using sxiv (Simple X Image Viewer) through a terminal, quit command on the terminal instead of the sxiv program will cause the issue as well.

wongweilok commented 3 years ago

https://user-images.githubusercontent.com/49401808/112263115-bccf5c80-8ca9-11eb-9fe7-82787bcb78da.mp4

This is another approach to reproduce the issue. I found this one by accident when I was trying to find specific settings in the android studio. Based on this, I suspect that IPC can't handle too much event changes of window client opening and closing in extremely short amount of time.

croyleje commented 3 years ago

I have also experienced this issue or similar issue but it occurs when I open the 'Nextcloud Desktop Client' used to connect with a remote Nextcloud server. Only thing in the polybar logs is "polybar|error: module/dwm: [dwmipcpp] Client with window id 12582936 not found". I would be happy to help diagnose or supply logs if there is anything I can do to help please feel free to ask.

Interesting observation: If you log out and quit the xsession and then restart with xinit the bar will restart but the desktop section on the left displaying tags does not reappear.

If you use "polybar-msg cmd restart" the desktop section shows back up even with out logging out and back in.

Or I can kill the Nextcloud application and restart polybar.

croyleje commented 3 years ago

While doing some more digging into this situation I have learned that applications that cause this issue only seem to do so if I launch them from dmenu but if I launch these applications from the terminal just simply running the command the error does not seem to occur.

wongweilok commented 3 years ago

Update: With the recent release of Android Studio version 4.2, the dropdown menu no longer spawn as seperate window. Thus, the issue won't occur anymore when using Android Studio (4.2 and above). However, this issue can still be reproduce with other approaches stated in above comments. Especially the one that @croyleje stated.

gwagner commented 3 years ago

I am getting the same issue when opening OBS into the systray

==> dwm.log <==
[fd 6] Error: Client with window id 16777222 not found
Error handling IPC event on fd 6

==> polybar.logs <==
polybar|error: module/dwm: [dwmipcpp] Client with window id 16777222 not found
polybar|notice:  Stopping 'module/dwm'...

To fix, i am just restarting polybar

mihirlad55 commented 3 years ago

Sorry, I haven't had time to work on this, but if anyone wants to try a fix, I think this should be fixable by checking first if a window with the specified ID exists before fetching its title. The only problem I see with this solution is if the window is closed within the short period of time between checking if the window exists and fetching its title, the module will crash with this exact error. Another solution is to implement a WindowNotFound exception or similar in dwmipcpp and catching this exception in the polybar-dwm-module and just printing a warning rather than throwing an error. The latter solution may be the most robust.

mihirlad55 commented 3 years ago

On second thought, the above solutions may be more of a workaround than a direct solution. This could be masking a bug deeper in the code. It may be good to further investigate the root cause of the window Id's being received not belonging to an existing window.

gwagner commented 3 years ago

@mihirlad55 r u able to provide some links to suspect spots of the code? I would be happy to do some looking but am unfamiliar with either the module or the patch code to know where to start looking.

mihirlad55 commented 3 years ago

I recommend looking at https://github.com/mihirlad55/polybar-dwm-module/blob/master/src/modules/dwm.cpp#L443-L457 and https://github.com/mihirlad55/dwmipcpp/blob/master/src/connection.cpp#L375-L437

mihirlad55 commented 3 years ago

https://github.com/mihirlad55/polybar-dwm-module/blob/master/src/modules/dwm.cpp#L523-L527 and https://github.com/mihirlad55/dwm-ipc/blob/master/ipc.c#L1065-L1073 may also be useful if you want to dig deeper to find the root of the problem

DominickVale commented 2 years ago

The problem can also be reproduced by closing all the clients in a tag quickly. I tried looking at the source to spot the actual deeper bug but unfortunately, i don't have enough experience with either c/c++ or this project... The only thing i got out of it is that by the time that dwm replies to the module the window is already destroyed... As a workaround, i intercepted the ResultFailureError and just logged it instead of throwing an error. (For anyone that wants a quick "fix") https://github.com/DominickVale/polybar-dwm-module/commit/b20fd0c90295410001ab6397f3761951396980c1

aleister888 commented 2 years ago

There's an easy workaround for this: In your polybar config delete "label-title" (under [module/dwm]), so the module doesn't read the window title at all, then use [module/title] as a replacement.

xorsirenz commented 2 years ago

I was having the exact same issue with using the countdown timer with flameshot. Can confirm adding the [module/title] to the polybar config fixes the issue for me as well.