Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emacs 31: running commands that requires user input from message passing may break emacs #746

Open
blahgeek opened this issue Dec 4, 2024 · 0 comments

Comments

@blahgeek
Copy link
Contributor

blahgeek commented Dec 4, 2024

How to reproduce

  1. Use newest master version of emacs
  2. Create a large file (larger than large-file-warning-threshold)
  3. Use vterm_cmd find-file to open the file

Expected behavior

The usual "really open large file?" prompt is shown and opens the file.

Actual behavior

Emacs becomes non-responsive forever. "C-g" or other keys does not work at all.

Backtrace

(gdb) bt
#0  pselect64_syscall
    (sigmask=<optimized out>, timeout=<optimized out>, exceptfds=0x0, writefds=0x7fffffff8d90, readfds=0x7fffffff8d10, nfds=23)
    at ../sysdeps/unix/sysv/linux/pselect.c:34
#1  __pselect
    (nfds=23, readfds=0x7fffffff8d10, writefds=0x7fffffff8d90, exceptfds=0x0, timeout=<optimized out>, sigmask=<optimized out>)
    at ../sysdeps/unix/sysv/linux/pselect.c:56
#2  0x00005555557d7a8c in really_call_select (arg=0x7fffffff8c00)
    at thread.c:624
#3  0x00005555557d870f in flush_stack_call_func
    (arg=0x7fffffff8c00, func=0x5555557d7a20 <really_call_select>)
    at lisp.h:4524
#4  thread_select
    (func=<optimized out>, max_fds=max_fds@entry=23, rfds=rfds@entry=0x7fffffff8d10, wfds=wfds@entry=0x7fffffff8d90, efds=efds@entry=0x0, timeout=timeout@entry=0x7fffffff9360, sigmask=0x0) at thread.c:656
#5  0x0000555555808968 in xg_select
    (fds_lim=23, rfds=rfds@entry=0x7fffffff94d0, wfds=wfds@entry=0x7fffffff9550, efds=efds@entry=0x0, timeout=timeout@entry=0x7fffffff9360, sigmask=sigmask@entry=0x0) at xgselect.c:205
#6  0x00005555557b2f8b in wait_reading_process_output
    (time_limit=time_limit@entry=0, nsecs=nsecs@entry=0, read_kbd=read_kbd@entry=-1, do_display=true, wait_for_cell=wait_for_cell@entry=0x0, wait_proc=wait_proc@entry=0x0, just_wait_proc=0) at process.c:5746
#7  0x00005555556d9ab4 in kbd_buffer_get_event
    (end_time=0x0, used_mouse_menu=0x0, kbp=<synthetic pointer>) at lisp.h:1178
#8  read_event_from_main_queue
    (used_mouse_menu=0x0, local_getcjmp=0x7fffffff9960, end_time=0x0)
    at keyboard.c:2325
#9  read_decoded_event_from_main_queue
    (used_mouse_menu=<optimized out>, prev_event=<optimized out>, local_getcjmp=<optimized out>, end_time=<optimized out>) at keyboard.c:2389
#10 read_char
    (commandflag=commandflag@entry=0, map=map@entry=0x0, prev_event=prev_event@entry=0x30, used_mouse_menu=used_mouse_menu@entry=0x0, end_time=0x0)
    at keyboard.c:3021
#11 0x0000555555781e3b in read_filtered_event
    (no_switch_frame=false, ascii_required=false, error_nonascii=false, input_method=<optimized out>, seconds=0x0) at lisp.h:1178
#12 0x00005555557550d0 in Ffuncall (nargs=1, args=0x7fffffff9dc0)
    at eval.c:3079
#13 0x00007fffedf7e94f in F726561642d6d756c7469706c652d63686f6963652d2d73686f72742d616e7377657273_read_multiple_choice__short_answers_0 ()
    at /tmp/squashfs-root/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-0b45e146/preloaded/rmc-9c382b5d-8a589e38.eln
#14 0x00005555557550d0 in Ffuncall (nargs=5, args=0x7fffffff9e40)
    at eval.c:3079
#15 0x00007fffedf7e121 in F726561642d6d756c7469706c652d63686f696365_read_multiple_choice_0 ()
    at /tmp/squashfs-root/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-0b45e146/preloaded/rmc-9c382b5d-8a589e38.eln
#16 0x00005555557550d0 in Ffuncall (nargs=4, args=0x7fffffff9f20)
    at eval.c:3079
#17 0x00007fffee4759c2 in F66696c65732d2d61736b2d757365722d61626f75742d6c617267652d66696c65_files__ask_user_about_large_file_0 ()
    at /tmp/squashfs-root/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-0b45e146/preloaded/files-1e8937b2-a64d80f7.eln
#18 0x00005555557550d0 in Ffuncall (nargs=5, args=0x7fffffff9fd0)
    at eval.c:3079
#19 0x00007fffee475bab in F61626f72742d69662d66696c652d746f6f2d6c61726765_abort_if_file_too_large_0 ()
    at /tmp/squashfs-root/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-0b45e146/preloaded/files-1e8937b2-a64d80f7.eln
#20 0x00005555557550d0 in Ffuncall (nargs=5, args=0x7fffffffa0c8)
    at eval.c:3079
#21 0x00007fffee476e75 in F66696e642d66696c652d6e6f73656c656374_find_file_noselect_0 ()
    at /tmp/squashfs-root/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-0b45e146/preloaded/files-1e8937b2-a64d80f7.eln
#22 0x00005555557550d0 in Ffuncall (nargs=5, args=0x7fffffffa170)
    at eval.c:3079
#23 0x00007fffee47406f in F66696e642d66696c65_find_file_0 ()
    at /tmp/squashfs-root/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-0b45e146/preloaded/files-1e8937b2-a64d80f7.eln
#24 0x000055555575874e in eval_sub (form=<optimized out>) at lisp.h:752
#25 0x000055555575a0e7 in internal_lisp_condition_case
    (var=0x2f19a20, bodyform=0x55555acf1de3, handlers=<optimized out>)
    at eval.c:1533
#26 0x0000555555758604 in eval_sub (form=<optimized out>) at lisp.h:752
#27 0x0000555555758c90 in Fprogn (body=<optimized out>) at eval.c:439
#28 funcall_lambda (fun=0x55555be3767d, nargs=1, arg_vector=0x7fffffffa4f8)
    at eval.c:3336
#29 0x00005555557550d0 in Ffuncall
    (nargs=nargs@entry=2, args=args@entry=0x7fffffffa4f0) at eval.c:3079
#30 0x0000555555755662 in Fapply (nargs=2, args=0x7fffffffa4f0) at eval.c:2708
#31 0x0000555555758491 in eval_sub (form=<optimized out>) at eval.c:2556
#32 0x0000555555758604 in eval_sub (form=<optimized out>) at lisp.h:752
#33 0x0000555555759c60 in Fprogn (body=<optimized out>) at eval.c:439
#34 FletX (args=0x555559e8a0e3) at eval.c:1042
#35 0x0000555555758604 in eval_sub (form=<optimized out>) at lisp.h:752
#36 0x0000555555759c60 in Fprogn (body=<optimized out>) at eval.c:439
#37 FletX (args=0x555559e8a043) at eval.c:1042
#38 0x0000555555758604 in eval_sub (form=<optimized out>) at lisp.h:752
#39 0x0000555555758c90 in Fprogn (body=<optimized out>) at eval.c:439
#40 funcall_lambda (fun=0x55555c20e525, nargs=1, arg_vector=0x7fffffffaa28)
    at eval.c:3336
#41 0x00005555557550d0 in Ffuncall
    (nargs=nargs@entry=2, args=args@entry=0x7fffffffaa20) at eval.c:3079
#42 0x0000555555755662 in Fapply (nargs=2, args=0x7fffffffaa20) at eval.c:2708
#43 0x00007fffce6f83bd in F767465726d2d2d6576616c_vterm__eval_0 ()
    at /home/yikai/.emacs.d/eln-cache/31.0.50-0b45e146/vterm-f27e86fd-309818c3.eln
#44 0x00005555557550d0 in Ffuncall
    (nargs=nargs@entry=2, args=args@entry=0x7fffffffaa90) at eval.c:3079
#45 0x000055555578e5b8 in module_funcall
    (env=0x7fffffffabd0, func=0x55555a9bae88, nargs=1, args=0x7fffffffab10)
    at emacs-module.c:679
#46 0x00007fffce6c285e in vterm_eval
    (env=env@entry=0x7fffffffabd0, string=<optimized out>)
    at /home/yikai/.emacs.d/lib/vterm/elisp.c:203
#47 0x00007fffce6bfbd9 in term_redraw
    (term=0x5555593667e0, env=env@entry=0x7fffffffabd0)
    at /home/yikai/.emacs.d/lib/vterm/vterm-module.c:637
#48 0x00007fffce6c003c in Fvterm_redraw
    (env=0x7fffffffabd0, nargs=<optimized out>, args=<optimized out>, data=<optimized out>) at /home/yikai/.emacs.d/lib/vterm/vterm-module.c:1340
#49 0x000055555578f30a in funcall_module
    (function=0x55555a9baf45, nargs=1, arglist=0x7fffffffbe48)
    at emacs-module.c:1296
#50 0x00005555557550d0 in Ffuncall
    (nargs=nargs@entry=2, args=args@entry=0x7fffffffbe40) at eval.c:3079
#51 0x0000555555755662 in Fapply (nargs=2, args=0x7fffffffbe40) at eval.c:2708
#52 0x0000555555758491 in eval_sub (form=<optimized out>) at eval.c:2556
#53 0x0000555555758604 in eval_sub (form=<optimized out>) at lisp.h:752
#54 0x0000555555758c90 in Fprogn (body=<optimized out>) at eval.c:439
#55 funcall_lambda (fun=0x55555ac5bd75, nargs=2, arg_vector=0x7fffffffc050)
    at eval.c:3336
#56 0x0000555555759649 in apply_lambda
    (fun=0x55555ac5bd75, args=<optimized out>, count=count@entry=...)
    at eval.c:3201
#57 0x0000555555758017 in eval_sub (form=<optimized out>) at eval.c:2673
#58 0x0000555555758c90 in Fprogn (body=<optimized out>) at eval.c:439
#59 funcall_lambda (fun=0x55555ac5bda5, nargs=2, arg_vector=0x7fffed1ff048)
    at eval.c:3336
#60 0x00005555557550d0 in Ffuncall
    (nargs=nargs@entry=3, args=args@entry=0x7fffed1ff040) at eval.c:3079
#61 0x0000555555755662 in Fapply (nargs=3, args=0x7fffed1ff040) at eval.c:2708
#62 0x000055555579cdd2 in exec_byte_code
    (fun=<optimized out>, args_template=<optimized out>, nargs=<optimized out>, args=<optimized out>) at lisp.h:752
#63 0x00005555557550d0 in Ffuncall (nargs=2, args=0x7fffffffc3d0)
    at eval.c:3079
#64 0x00007fffce6f6561 in F767465726d2d2d64656c617965642d726564726177_vterm__delayed_redraw_0 ()
    at /home/yikai/.emacs.d/eln-cache/31.0.50-0b45e146/vterm-f27e86fd-309818c3.eln
#65 0x00005555557550d0 in Ffuncall
    (nargs=nargs@entry=2, args=args@entry=0x7fffffffc520) at eval.c:3079
#66 0x0000555555755662 in Fapply (nargs=2, args=0x7fffffffc520) at eval.c:2708
#67 0x00005555557550d0 in Ffuncall (nargs=3, args=0x7fffffffc518)
    at eval.c:3079
#68 0x00007fffee19bfc8 in F74696d65722d6576656e742d68616e646c6572_timer_event_handler_0 ()
    at /tmp/squashfs-root/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-0b45e146/preloaded/timer-3ee7cfd9-4017b895.eln
#69 0x00005555557550d0 in Ffuncall
    (nargs=nargs@entry=2, args=args@entry=0x7fffffffc600) at eval.c:3079
#70 0x00005555556d45d9 in timer_check_2
    (idle_timers=<optimized out>, timers=0x55555ba52bc3) at lisp.h:1178
#71 timer_check () at keyboard.c:4870
#72 0x00005555556d48f5 in readable_events (flags=flags@entry=1)
    at keyboard.c:3602
#73 0x00005555556d4b28 in get_input_pending (flags=flags@entry=1)
    at keyboard.c:7873
#74 0x00005555556d7e38 in detect_input_pending_run_timers
    (do_display=do_display@entry=true) at keyboard.c:11577
#75 0x00005555557b2a1c in wait_reading_process_output
    (time_limit=time_limit@entry=0, nsecs=nsecs@entry=0, read_kbd=read_kbd@entry=-1, do_display=true, wait_for_cell=wait_for_cell@entry=0x0, wait_proc=wait_proc@entry=0x0, just_wait_proc=0) at process.c:5842
#76 0x00005555556d9ab4 in kbd_buffer_get_event
    (end_time=0x0, used_mouse_menu=0x7fffffffd1cb, kbp=<synthetic pointer>)
    at lisp.h:1178
#77 read_event_from_main_queue
    (used_mouse_menu=0x7fffffffd1cb, local_getcjmp=0x7fffffffcde0, end_time=0x0)
 at keyboard.c:2325
#78 read_decoded_event_from_main_queue
    (used_mouse_menu=<optimized out>, prev_event=<optimized out>, local_getcjmp=
<optimized out>, end_time=<optimized out>) at keyboard.c:2389
#79 read_char
    (commandflag=1, map=0x55555ba53963, prev_event=0x0, used_mouse_menu=0x7fffff
ffd1cb, end_time=0x0) at keyboard.c:3021
#80 0x00005555556dbbb4 in read_key_sequence
    (keybuf=0x7fffffffd340, prompt=0x0, dont_downcase_last=<optimized out>, can_
return_switch_frame=true, fix_current_buffer=true, prevent_redisplay=<optimized 
out>, disable_text_conversion_p=false) at keyboard.c:10747
#81 0x00005555556dd48f in command_loop_1 () at lisp.h:1178
#82 0x0000555555753a52 in internal_condition_case
    (bfun=bfun@entry=0x5555556dd2c0 <command_loop_1>, handlers=handlers@entry=0x
90, hfun=hfun@entry=0x5555556d1e70 <cmd_error>) at eval.c:1607
#83 0x00005555556ca852 in command_loop_2 (handlers=handlers@entry=0x90)
    at keyboard.c:1163
#84 0x0000555555753981 in internal_catch
    (tag=tag@entry=0x12390, func=func@entry=0x5555556ca830 <command_loop_2>, arg
=arg@entry=0x90) at eval.c:1286
#85 0x00005555556ca7ee in command_loop () at lisp.h:1178
#86 0x00005555556d19e6 in recursive_edit_1 () at keyboard.c:749
#87 0x00005555556d1d94 in Frecursive_edit () at keyboard.c:832
#88 0x00005555555aa88d in main (argc=<optimized out>, argv=<optimized out>)
    at emacs.c:2625

Possible fix

Running commands directly during redraw (which is during reading process outputs) seems flaky. I think we should use (run-with-timer 0 ...) to defer the command execution. I can confirm that using run-with-timer can fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant