bspwm icon indicating copy to clipboard operation
bspwm copied to clipboard

Bspwm crashes when laptop is waking up from suspend and monitors are unplugged

Open btaczala opened this issue 5 years ago • 12 comments

This happens from time to time; when I put my laptop in suspend mode, unplug connected monitors and then wake laptop bspwm crashes. Backtrace:

coredumpctl dump bspwm | pbcopy                                                                                                                                                                                                                        new_sgrc ✗
           PID: 783 (bspwm)
           UID: 1000 (bartek)
           GID: 1000 (bartek)
        Signal: 11 (SEGV)
     Timestamp: Tue 2019-02-19 15:58:20 CET (2h 29min ago)
  Command Line: bspwm
    Executable: /usr/bin/bspwm
 Control Group: /user.slice/user-1000.slice/session-1.scope
          Unit: session-1.scope
         Slice: user-1000.slice
       Session: 1
     Owner UID: 1000 (bartek)
       Boot ID: f2a10a26dbbc4e91a1e171dd99342aa0
    Machine ID: 329f0c0bb8a84b0883dd1d4ca0ed7dfa
      Hostname: bartek-t470p
       Storage: /var/lib/systemd/coredump/core.bspwm.1000.f2a10a26dbbc4e91a1e171dd99342aa0.783.1550588300000000.lz4
       Message: Process 783 (bspwm) of user 1000 dumped core.
                
                Stack trace of thread 783:
                #0  0x000055e08625754d focus_in (bspwm)
                #1  0x000055e08625685f handle_event (bspwm)
                #2  0x000055e086249507 main (bspwm)
                #3  0x00007fac2c313223 __libc_start_main (libc.so.6)
                #4  0x000055e086248b0e _start (bspwm)
More than one entry matches, ignoring rest.

The crash happens in src/events.c

if (mon->desk->focus != NULL && e->event == mon->desk->focus->id) {

mon is 0x0 in this expression hence the crash. The easy way to fix this is to change the line to:

if (mon && mon->desk && mon->desk->focus != NULL && e->event == mon->desk->focus->id) {

I can obviously fix this but perhaps this is a symptom of something bigger that should be fixed.

B

btaczala avatar Feb 19 '19 17:02 btaczala

The problem is that mon != NULL is assumed almost everywhere. If mon (the focused monitor) is NULL, it means that every monitor known to bspwm was removed…

So the question here is: what leads to mon == NULL?

baskerville avatar Feb 19 '19 19:02 baskerville

One thing worth mentioning is that this mostly happens when I undock the laptop from docking station, while in suspend. But I guess this is similar to unlogging the monitor as X output are still there just unplugged

btaczala avatar Feb 19 '19 20:02 btaczala

I'm having the same problem. Did you ever find a solution to this?

KLIM8D avatar Apr 13 '20 15:04 KLIM8D

I'm also having the same problem when I dock my laptop. The builtin display is turned --off at the same time the external displays are enabled.

xrandr --output eDP1 --off \
       --output DP2-1 --mode 3840x2160 --rate 30.00 --left-of DP2-2-8 --primary \
       --output DP2-2-8 --mode 3840x2160 --rate 29.98
Core was generated by `bspwm'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000560b181f954a in focus_in (evt=<optimized out>) at src/events.c:351
351	src/events.c: No such file or directory.
(gdb) bt
#0  0x0000560b181f954a in focus_in (evt=<optimized out>) at src/events.c:351
#1  0x0000560b181ee4c9 in main (argc=1, argv=0x7ffe3df91d78) at src/bspwm.c:206

Which corresponds to the same spot in events.c: https://github.com/baskerville/bspwm/blob/2ffd9c140932c5be638f7d9cefd045e03f5f6f42/src/events.c#L351-L353

terinjokes avatar Apr 13 '20 18:04 terinjokes

It seems like it doesn't occur that often (like almost never) if I set both remove_disabled_monitors and remove_unplugged_monitors to false before I suspend/hibernate my laptop.

wm_suspend() {
    bspc config remove_disabled_monitors false
    bspc config remove_unplugged_monitors false
    systemctl suspend
}

To "adapt" to the new changes that can be to the monitor setup I've subscribed in my bspwm config with the following

bspc subscribe monitor | while read -r line; do
  case $line in
      monitor_add*|monitor_geometry*)
        setup_desktops
        #setup_panels
      ;;
      monitor_remove*)
        /usr/bin/autorandr --change
      ;;
      *)
      ;;
  esac
done &

(https://github.com/phillipberndt/autorandr/)

KLIM8D avatar Apr 17 '20 08:04 KLIM8D

also running into this issue, I think the window manager should be able to handle this correctly, what could be done in order to prevent this?

deviantfero avatar Jul 27 '20 16:07 deviantfero

@baskerville bspwm is my favorite wm but this is keeping me from using it as I use a docking station and can't afford to be crashing my wm each time I decide to remove my laptop from it's dock, is there any work on this on the way? or maybe we could setup a "ghost" desktop to serve as fallback while there's no connected monitors

deviantfero avatar Nov 02 '20 15:11 deviantfero

@deviantfero I've managed to get around this issue by using xrandr to "wake up" my laptop monitor, before it is suspended. The above "fix" I mentioned in the previous comment had somtimes some issues with the subscribe and I'm not using that anymore

My suspend function now looks like this

wm_suspend() {
    ps -fC "bspwm" > /dev/null
    if [ $? -eq 0 ]; then
        bspc config remove_disabled_monitors false
        bspc config remove_unplugged_monitors false
        xrandr --output eDP-1 --auto
    fi

    #lock && systemctl suspend
    lock && systemctl hybrid-sleep
}

And I'm still using autorandr with a postswitch/posthook script that then (re)applies my bspwm settings after I resume. I haven't experienced a crash for many months now.

KLIM8D avatar Nov 02 '20 15:11 KLIM8D

My biggest problem is undocking my laptop, since I can't turn on my laptop monitor beforehand at least not in a script. docking is possible with those settings you've shared, but undocking still requires some manual intervention.

deviantfero avatar Nov 02 '20 17:11 deviantfero

I don't think this is even related with suspending. Undocking when your laptop screen is disabled (off), will cause the same problem. How would you enable it before BSPWM crashes?

davidmogar avatar May 18 '21 14:05 davidmogar

Maybe related. I am having an issue, that suspending from GDM works. But not from BSPWM. I use a dock, but I do not unplug any monitors.

However, I have got these: bspc config remove_disabled_monitors true bspc config remove_unplugged_monitors true

In my case, BSPWM does not crash. I couldn't find any errors. The screen is black but the backlight is active and the only way to gain control back is to restart my computer via the power button. (TTY shortcuts are not working)

But @KLIM8D's answer helped.

fxdave avatar Jan 02 '22 14:01 fxdave

I don't think this is even related with suspending. Undocking when your laptop screen is disabled (off), will cause the same problem.

I can confirm this; it also includes monitors that have gone into power-save mode via (e.g.) dpms. This also affects the built-in monitor of laptops, which can also be turned off by dpms, so plugging in a dock or monitors while the screen is blanked causes bspwm to crash.

I haven't yet identified which combination of settings is involved (remove_disabled_monitors, remove_unplugged_monitors, or both), but it is certainly true that there are multiple situations where mon will be null

xxxserxxx avatar Jun 10 '22 17:06 xxxserxxx