* bug#32487: 26.1.50; keyboard-quit while main thread blocked crashes Emacs
@ 2018-08-20 22:57 Gemini Lasswell
2018-08-21 15:22 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Gemini Lasswell @ 2018-08-20 22:57 UTC (permalink / raw)
To: 32487
In both emacs-26 and master, it's possible to hang or crash Emacs with
Lisp code which uses threads and is buggy in ways which cause the main
thread to be blocked, combined with keyboard-quit.
To reproduce, copy the code listed below into a buffer and evaluate it
(with emacs -Q if you wish). Then choose one of:
M-x my-hang-1 RET
M-x my-hang-2 RET
M-x my-hang-3 RET
Result: Emacs will stop responding to keyboard input. Repeated use of
C-g will do nothing when running under X11 and will cause Emacs to crash
when running in a terminal.
(defvar my-mutex-1 (make-mutex "mutex-1"))
(defun my-wait-on-locked-mutex ()
(with-mutex my-mutex-1
(message "mutex-1 wasn't locked")))
(defun my-hang-1 ()
(interactive)
(with-mutex my-mutex-1
(let ((thread (make-thread #'my-wait-on-locked-mutex)))
(thread-join thread))))
(defvar my-mutex-2 (make-mutex "mutex-2"))
(defvar my-var-2 nil)
(defun my-inf-loop ()
(mutex-lock my-mutex-2)
(while t
(setq my-var-2 t)
(thread-yield)))
(defun my-hang-2 ()
(interactive)
(setq my-var-2 nil)
(let ((thread (make-thread #'my-inf-loop)))
(while (not my-var-2)
(thread-yield))
(with-mutex my-mutex-2
(message "mutex-2 wasn't locked"))))
(defvar my-cond-mutex (make-mutex "cond-mutex"))
(defvar my-cond-var (make-condition-variable my-cond-mutex))
(defvar my-var-3 nil)
(defun my-fail-to-notify ()
(with-mutex my-cond-mutex
(setq my-var-3 t)))
(defun my-hang-3 ()
(interactive)
(setq my-var-3 nil)
(let ((thread (make-thread #'my-fail-to-notify)))
(with-mutex my-cond-mutex
(while (not my-var-3)
(condition-wait my-cond-var)))))
In GNU Emacs 26.1.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.28)
of 2018-08-05 built on localhost
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Configured using:
'configure
--prefix=/nix/store/4pwyx7ixl5fbdj75kmbsnzcrbsvkvg09-emacs-26.1.50
--with-modules --with-x-toolkit=gtk3 --with-xft'
Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND DBUS GSETTINGS NOTIFY
LIBSELINUX GNUTLS LIBXML2 FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11
MODULES THREADS LCMS2
Important settings:
value of $EMACSLOADPATH: /nix/store/7xj2afwwci2r69g5ghhf7qlinlpxw858-emacs-packages-deps/share/emacs/site-lisp:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
Major mode: Lisp Interaction
Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
Load-path shadows:
/nix/store/7xj2afwwci2r69g5ghhf7qlinlpxw858-emacs-packages-deps/share/emacs/site-lisp/elpa/magit-2.11.0/magit-popup hides /nix/store/7xj2afwwci2r69g5ghhf7qlinlpxw858-emacs-packages-deps/share/emacs/site-lisp/elpa/magit-popup-2.12.2/magit-popup
/nix/store/7xj2afwwci2r69g5ghhf7qlinlpxw858-emacs-packages-deps/share/emacs/site-lisp/elpa/soap-client-3.1.3/soap-inspect hides /nix/store/4pwyx7ixl5fbdj75kmbsnzcrbsvkvg09-emacs-26.1.50/share/emacs/26.1.50/lisp/net/soap-inspect
/nix/store/7xj2afwwci2r69g5ghhf7qlinlpxw858-emacs-packages-deps/share/emacs/site-lisp/elpa/soap-client-3.1.3/soap-client hides /nix/store/4pwyx7ixl5fbdj75kmbsnzcrbsvkvg09-emacs-26.1.50/share/emacs/26.1.50/lisp/net/soap-client
/nix/store/7xj2afwwci2r69g5ghhf7qlinlpxw858-emacs-packages-deps/share/emacs/site-lisp/elpa/seq-2.20/seq hides /nix/store/4pwyx7ixl5fbdj75kmbsnzcrbsvkvg09-emacs-26.1.50/share/emacs/26.1.50/lisp/emacs-lisp/seq
/nix/store/7xj2afwwci2r69g5ghhf7qlinlpxw858-emacs-packages-deps/share/emacs/site-lisp/elpa/let-alist-1.0.5/let-alist hides /nix/store/4pwyx7ixl5fbdj75kmbsnzcrbsvkvg09-emacs-26.1.50/share/emacs/26.1.50/lisp/emacs-lisp/let-alist
Features:
(shadow sort mail-extr emacsbug message rmc puny seq seq-25 byte-opt gv
bytecomp byte-compile cconv cl-loaddefs cl-lib dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils elec-pair time-date
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)
Memory information:
((conses 16 95020 4549)
(symbols 48 20383 1)
(miscs 40 44 118)
(strings 32 28447 1654)
(string-bytes 1 773489)
(vectors 16 14062)
(vector-slots 8 502938 6272)
(floats 8 49 68)
(intervals 56 216 0)
(buffers 992 11))
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#32487: 26.1.50; keyboard-quit while main thread blocked crashes Emacs
2018-08-20 22:57 bug#32487: 26.1.50; keyboard-quit while main thread blocked crashes Emacs Gemini Lasswell
@ 2018-08-21 15:22 ` Eli Zaretskii
2018-08-22 14:39 ` Gemini Lasswell
0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2018-08-21 15:22 UTC (permalink / raw)
To: Gemini Lasswell; +Cc: 32487
> From: Gemini Lasswell <gazally@runbox.com>
> Date: Mon, 20 Aug 2018 15:57:08 -0700
>
> In both emacs-26 and master, it's possible to hang or crash Emacs with
> Lisp code which uses threads and is buggy in ways which cause the main
> thread to be blocked, combined with keyboard-quit.
That's ample punishment for a buggy program, don't you think?
> To reproduce, copy the code listed below into a buffer and evaluate it
> (with emacs -Q if you wish). Then choose one of:
>
> M-x my-hang-1 RET
> M-x my-hang-2 RET
> M-x my-hang-3 RET
>
> Result: Emacs will stop responding to keyboard input. Repeated use of
> C-g will do nothing when running under X11 and will cause Emacs to crash
> when running in a terminal.
Doing nothing is fine when a program is buggy.
On a TTY, the 1st and the 3rd example are not crashes: they are the
"emergency escape" feature of Emacs. You can read about it in the
manual. It is triggered when more than one C-g is pressed without
Emacs being able to process the first one. Due to the way we process
input nowadays, you cannot see this in action except on a Unix TTY,
where C-g triggers a SIGINT.
The 2nd example seems to be caused by a non-main thread entering
redisplay (I think). Or something like that.
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#32487: 26.1.50; keyboard-quit while main thread blocked crashes Emacs
2018-08-21 15:22 ` Eli Zaretskii
@ 2018-08-22 14:39 ` Gemini Lasswell
2018-08-22 15:06 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Gemini Lasswell @ 2018-08-22 14:39 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 32487
Eli Zaretskii <eliz@gnu.org> writes:
> That's ample punishment for a buggy program, don't you think?
I thought so too at first, when I first came across this. But the
reality is that new bugs get added to Emacs all the time, despite our
best efforts, and the fact that C-g can't interrupt the thread
primitives raises the risk of new bugs being severe bugs.
If a user encounters a hanging bug in non-threaded Lisp, it's very
likely that she can recover from it with C-g, and continue using Emacs.
But if the user encounters a hanging bug in threaded Lisp, she will lose
her Emacs session.
Emacs is also a development environment, and it's a much less friendly
place to develop programs when it's easy for buggy programs to crash the
development environment. Obviously it's not hard to write Lisp that
makes Emacs unresponsive or unusable, if you're trying to do that. But
in the act of trying to write useful Lisp, it's been rare in my
experience. With the thread primitives it's much easier to do
unintentionally.
Most of the time when I write buggy Lisp that stops responding, I can
find out what the problem is by stopping it with C-g, using
toggle-debug-on-quit, restarting my problematic code, C-g again. This
doesn't work if the main thread is stuck in a thread primitive.
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#32487: 26.1.50; keyboard-quit while main thread blocked crashes Emacs
2018-08-22 14:39 ` Gemini Lasswell
@ 2018-08-22 15:06 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2018-08-22 15:06 UTC (permalink / raw)
To: Gemini Lasswell; +Cc: 32487
> From: Gemini Lasswell <gazally@runbox.com>
> Cc: 32487@debbugs.gnu.org
> Date: Wed, 22 Aug 2018 07:39:35 -0700
>
> Most of the time when I write buggy Lisp that stops responding, I can
> find out what the problem is by stopping it with C-g, using
> toggle-debug-on-quit, restarting my problematic code, C-g again. This
> doesn't work if the main thread is stuck in a thread primitive.
It also doesn't always work if you are stuck in a system API.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-08-22 15:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-20 22:57 bug#32487: 26.1.50; keyboard-quit while main thread blocked crashes Emacs Gemini Lasswell
2018-08-21 15:22 ` Eli Zaretskii
2018-08-22 14:39 ` Gemini Lasswell
2018-08-22 15:06 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).