baskerville / bspwm

A tiling window manager based on binary space partitioning
BSD 2-Clause "Simplified" License
7.8k stars 415 forks source link

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

Open btaczala opened 5 years ago

btaczala commented 5 years ago

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

baskerville commented 5 years ago

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?

btaczala commented 5 years ago

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

KLIM8D commented 4 years ago

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

terinjokes commented 4 years ago

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

KLIM8D commented 4 years ago

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/)

deviantfero commented 4 years ago

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 commented 4 years ago

@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

KLIM8D commented 4 years ago

@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.

deviantfero commented 4 years ago

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.

davidmogar commented 3 years ago

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?

fxdave commented 2 years ago

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.

xxxserxxx commented 2 years ago

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