As it happened again, I'll attach the backtrace from the emacs thread at the time. Then I'll restart with an empty DISPLAY and see what happens.