emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.75k stars 872 forks source link

Doom Emacs segfaults when using LSP #4510

Open hyperreal64 opened 1 month ago

hyperreal64 commented 1 month ago

Thank you for the bug report

Bug description

When using the Go or Python LSP, the LSP is initialized and after a few seconds it causes Emacs to crash. It seems to be related to this bug. I ran Emacs from the terminal and then reproduced the crash. The backtrace is in the screenshot below. I'm not sure how else to debug this, but I would be more than happy to provide any other information and/or help run tests on my end. 4746832201e9d28a

Steps to reproduce

On my machine, all I have to do is open a Python or Go project, let the LSP initialize, start typing code, and then it segfaults.

Expected behavior

Emacs doesn't segfault.

Which Language Server did you use?

lsp-python, lsp-go

OS

Linux

Error callstack

No response

Anything else?

No response

hyperreal64 commented 1 month ago

UPDATE: I was using Emacs version 29.4 from the Fedora package repositories.

I've compiled version 28.2 from source and so far there aren't any segfaults when using LSP.

psibi commented 1 month ago

Can you also reproduce the bug in Emacs 29.4 without using doom emacs but just using plain lsp-mode ?

luciusmagn commented 1 month ago

I have the same issue. I tried both vanilla emacs 29.4 and emacs-wayland.

This is my stacktrace:

Fatal error 11: Segmentation fault
Backtrace:
emacs(+0x13d374) [0x557b7b228374]
emacs(+0x1fcd0) [0x557b7b10acd0]
emacs(+0x20e52) [0x557b7b10be52]
emacs(+0x29f03d) [0x557b7b38a03d]
/usr/lib/libc.so.6(+0x3c5b0) [0x557b76ac05b0]
emacs(+0x1c61a8) [0x557b7b2b11a8]
emacs(+0x127eef) [0x557b7b212eef]
emacs(+0x1352c8) [0x557b7b2202c8]
emacs(+0x1242c7) [0x557b7b20f2c7]
emacs(+0x1e5f31) [0x557b7b2d0f31]
/usr/bin/../lib/emacs/29.4/native-lisp/29.4-a0810582/preloaded/subr-13adf6a6-bfb9f448.eln(F7369742d666f72_sit_for_0+0x1c7) [0x557b73560337]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
/root/.config/emacs/.local/cache/eln/29.4-a0810582/lsp-mode-6666b574-6ee62a7e.eln(F6c73702d726571756573742d7768696c652d6e6f2d696e707574_lsp_request_while_no_input_0+0x447) [0x557b6c163b57]
emacs(+0x20b4fe) [0x557b7b2f64fe]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
emacs(+0x15b5df) [0x557b7b2465df]
emacs(+0x20b4fe) [0x557b7b2f64fe]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
/usr/bin/../lib/emacs/29.4/native-lisp/29.4-a0810582/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d2d736f6d65_completion__some_0+0x202) [0x557b725ba8f2]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
/usr/bin/../lib/emacs/29.4/native-lisp/29.4-a0810582/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d2d6e74682d636f6d706c6574696f6e_completion__nth_completion_0+0x2e4) [0x557b725bff24]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
/usr/bin/../lib/emacs/29.4/native-lisp/29.4-a0810582/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d616c6c2d636f6d706c6574696f6e73_completion_all_completions_0+0x5e) [0x557b725c033e]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
emacs(+0x1b8b20) [0x557b7b2a3b20]
emacs(+0x20b4fe) [0x557b7b2f64fe]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
/root/.config/emacs/.local/cache/eln/29.4-a0810582/company-capf-997787ee-0ccac283.eln(F636f6d70616e792d636170662d2d63616e646964617465732d31_company_capf__candidates_1_0+0x39d) [0x557b6d17a7fd]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
/root/.config/emacs/.local/cache/eln/29.4-a0810582/company-capf-997787ee-0ccac283.eln(F636f6d70616e792d636170662d2d63616e64696461746573_company_capf__candidates_0+0x1ad) [0x557b6d17a11d]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
emacs(+0x1b8e0a) [0x557b7b2a3e0a]
emacs(+0x1b9ea4) [0x557b7b2a4ea4]
emacs(+0x1baf4d) [0x557b7b2a5f4d]
emacs(+0x1b9c66) [0x557b7b2a4c66]
emacs(+0x1bbd4d) [0x557b7b2a6d4d]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
emacs(+0x1b8e0a) [0x557b7b2a3e0a]
emacs(+0x20b4fe) [0x557b7b2f64fe]
emacs(+0x1b7c6e) [0x557b7b2a2c6e]
/root/.config/emacs/.local/cache/eln/29.4-a0810582/company-capf-997787ee-0ccac283.eln(F636f6d70616e792d63617066_company_capf_0+0x23f) [0x557b6d178b4f]
...
fish: Job 1, 'emacs' terminated by signal SIGSEGV (Address boundary error)
hyperreal64 commented 1 month ago

Emacs 29.4 seems to run fine in plain LSP mode but I didn't test it for very long. I had a Python project opened with LSP mode enabled and was able to use it for a while until it crashed again. Here is the backtrace from said crash, which might give a clue as to the cause. It looks like company has something to do with it this time, same as for @luciusmagn. I do notice that the crash only happens when the code completion menu pops up. I'm going to try disabling company and using corfu.

Fatal error 11: Segmentation fault
Backtrace:
/usr/bin/emacs(emacs_backtrace+0x5a)[0x5982ea]
/usr/bin/emacs(terminate_due_to_signal+0x9f)[0x4678b5]
/usr/bin/emacs[0x468653]
/usr/bin/emacs[0x7116c4]
/lib64/libc.so.6(+0x40d00)[0x7fe18c84fd00]
/usr/bin/emacs(parse_modifiers+0x104)[0x57c2e4]
/usr/bin/emacs[0x5930c8]
/usr/bin/emacs(read_char+0x218a)[0x581b7a]
/usr/bin/emacs[0x64d282]
/usr/bin/../lib64/emacs/29.4/native-lisp/29.4-95d1479c/preloaded/subr-13adf6a6-bfb9f448.eln(F7369742d666f72_sit_for_0+0x19f)[0x7fe186b623af]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/home/jas/.config/emacs/.local/cache/eln/29.4-95d1479c/lsp-mode-4bd57f83-6ee62a7e.eln(F6c73702d726571756573742d7768696c652d6e6f2d696e707574_lsp_request_while_no_input_0+0x427)[0x7fe16d6108f7]
/usr/bin/emacs(exec_byte_code+0x56c)[0x6701bc]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/usr/bin/emacs(Fall_completions+0x372)[0x5b8c42]
/usr/bin/emacs(exec_byte_code+0x56c)[0x6701bc]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/usr/bin/../lib64/emacs/29.4/native-lisp/29.4-95d1479c/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d2d736f6d65_completion__some_0+0x1e2)[0x7fe185ba9852]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/usr/bin/../lib64/emacs/29.4/native-lisp/29.4-95d1479c/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d2d6e74682d636f6d706c6574696f6e_completion__nth_completion_0+0x2d4)[0x7fe185bae914]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/usr/bin/../lib64/emacs/29.4/native-lisp/29.4-95d1479c/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d616c6c2d636f6d706c6574696f6e73_completion_all_completions_0+0x50)[0x7fe185baecd0]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/usr/bin/emacs(Fapply+0x1b0)[0x6255c0]
/usr/bin/emacs(exec_byte_code+0x56c)[0x6701bc]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/home/jas/.config/emacs/.local/cache/eln/29.4-95d1479c/company-capf-b4167445-0ccac283.eln(F636f6d70616e792d636170662d2d63616e646964617465732d31_company_capf__candidates_1_0+0x36d)[0x7fe16e61664d]
/usr/bin/emacs(exec_byte_code+0x56c)[0x6701bc]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/usr/bin/emacs(Fapply+0x4a2)[0x6258b2]
/usr/bin/emacs(eval_sub+0xa57)[0x61a797]
/usr/bin/emacs(Flet+0x2cd)[0x61b84d]
/usr/bin/emacs(eval_sub+0x839)[0x61a579]
/usr/bin/emacs[0x6249bd]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/usr/bin/emacs(Fapply+0x4a2)[0x6258b2]
/usr/bin/emacs(exec_byte_code+0x56c)[0x6701bc]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/home/jas/.config/emacs/.local/cache/eln/29.4-95d1479c/company-capf-b4167445-0ccac283.eln(F636f6d70616e792d63617066_company_capf_0+0x22f)[0x7fe16e614a5f]
/usr/bin/emacs(Ffuncall+0xfd)[0x624ead]
/home/jas/.config/emacs/.local/cache/eln/29.4-95d1479c/company-a57d1860-b64d4357.eln(F636f6d70616e792d2d6d756c74692d6261636b656e642d616461707465722d63616e64696461746573_company__multi_backend_adapter_candidates_0+0x9c)[0x7fe16f75091c]
...
[1]    183834 segmentation fault (core dumped)  /usr/bin/emacs
hyperreal64 commented 1 month ago

I haven't had any issues using corfu so far. I'm going to try using LSP mode with lsp-start-plain with company enabled for a while and see how it goes.

luciusmagn commented 1 month ago

Hi, I can confirm that switching to corfu prevents the segfault

kiennq commented 1 month ago

Probably cross post on the company-mode repo as well?

kisaragi-hiu commented 1 month ago

Corresponding Doom issue: https://github.com/doomemacs/doomemacs/issues/7915. Though that issue suggests the problem is specific to Emacs 29, on my system it is still present after switching to git master (944e45d)

AFAIK we don't actually know if this is a company-mode, lsp-mode, Doom Emacs, or upstream Emacs issue. Or, rather, it's an upstream issue (Elisp is generally not supposed to cause segfaults), but we don't know how it shows up in this specific situation.

TL;DR after doing the debug runs below:


With a debugger I was able to trigger a crash on master (944e45d, with native-comp) with this message:

Thread 1 "emacs" received signal SIGSEGV, Segmentation fault.
0x000055555579a569 in Fget (symbol=<optimized out>, propname=XIL(0x7e00)) at ../../src/fns.c:2629
2629      return plist_get (XSYMBOL (symbol)->u.s.plist, propname);

The C backtrace:

C backtrace (all-completions ... unwind_protect ... read_filtered_event ... get) ```shellsession (gdb) bt #0 0x000055555579a569 in Fget (symbol=, propname=XIL(0x7e00)) at ../../src/fns.c:2629 #1 Fget (symbol=, propname=XIL(0x7e00)) at ../../src/fns.c:2618 #2 0x00005555556f2b00 in parse_modifiers (symbol=XIL(0x555556682540)) at ../../src/keyboard.c:7382 #3 parse_modifiers (symbol=XIL(0x555556682540)) at ../../src/keyboard.c:7373 #4 0x00005555557014e0 in reorder_modifiers (symbol=XIL(0x555556682540)) at ../../src/keyboard.c:7513 #5 access_keymap_1 (map=XIL(0x7fffefca71e3), idx=XIL(0x555556682540), t_ok=false, noinherit=false, autoload=true) at ../../src/keymap.c:342 #6 0x00005555556ee51f in access_keymap (noinherit=false, autoload=true, map=, idx=, t_ok=false) at ../../src/keymap.c:496 #7 read_char (commandflag=0, map=XIL(0), prev_event=XIL(0), used_mouse_menu=0x0, end_time=0x7fffffffa450) at ../../src/keyboard.c:3060 #8 0x00005555557ba955 in read_filtered_event (no_switch_frame=false, ascii_required=false, error_nonascii=false, input_method=, seconds=XIL(0x7ffff25e9aef)) at ../../src/lread.c:787 #9 0x00007ffff06b303f in F7369742d666f72_sit_for_0 () at /usr/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-b90a846c/preloaded/subr-13adf6a6-cdd9cb44.eln #10 0x0000555555786447 in eval_sub (form=) at ../../src/eval.c:2593 #11 0x0000555555786680 in Fprogn (body=, body@entry=XIL(0x5555643a9f93)) at ../../src/eval.c:439 #12 0x000055555578393a in internal_catch (tag=, func=0x555555786650 , arg=XIL(0x5555643a9f93)) at ../../src/eval.c:1292 #13 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #14 0x0000555555787540 in Fprogn (body=) at ../../src/eval.c:439 #15 prog_ignore (body=) at ../../src/eval.c:450 #16 Fwhile (args=) at ../../src/eval.c:1130 #17 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #18 0x0000555555786680 in Fprogn (body=) at ../../src/eval.c:439 #19 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #20 0x000055555578761b in Funwind_protect (args=XIL(0x5555643ab6e3)) at ../../src/lisp.h:1533 #21 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #22 0x0000555555786dd0 in Fprogn (body=) at ../../src/eval.c:439 #23 FletX (args=) at ../../src/eval.c:1042 #24 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #25 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #26 0x0000555555787ec0 in Fprogn (body=) at ../../src/eval.c:439 #27 funcall_lambda (fun=, nargs=, arg_vector=) at ../../src/eval.c:3342 #28 0x000055555578bee9 in apply_lambda (fun=, args=, count=count@entry=...) at ../../src/eval.c:3207 #29 0x0000555555785cd5 in eval_sub (form=) at ../../src/eval.c:2679 #30 0x0000555555786f42 in FletX (args=XIL(0x555556295f63)) at ../../src/eval.c:1017 #31 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #32 0x00005555557867f0 in Fprogn (body=) at ../../src/eval.c:439 #33 Fcond (args=XIL(0x555556295b43)) at ../../src/eval.c:419 #34 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #35 0x00005555557872e0 in Fprogn (body=) at ../../src/eval.c:439 #36 Flet (args=) at ../../src/eval.c:1109 #37 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #38 0x0000555555786680 in Fprogn (body=, body@entry=XIL(0x555556294f63)) at ../../src/eval.c:439 #39 0x000055555578393a in internal_catch (tag=, func=0x555555786650 , arg=XIL(0x555556294f63)) at ../../src/eval.c:1292 #40 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #41 0x0000555555787366 in Flet (args=) at ../../src/eval.c:1080 #42 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #43 0x0000555555787ec0 in Fprogn (body=) at ../../src/eval.c:439 #44 funcall_lambda (fun=, nargs=, arg_vector=) at ../../src/eval.c:3342 #45 0x00005555557885be in Ffuncall (nargs=1, args=0x7fffffffb300) at ../../src/eval.c:3085 --Type for more, q to quit, c to continue without paging--c #46 0x0000555555786500 in eval_sub (form=) at ../../src/eval.c:2562 #47 0x0000555555786307 in eval_sub (form=) at ../../src/eval.c:2578 #48 0x00005555557867f0 in Fprogn (body=) at ../../src/eval.c:439 #49 Fcond (args=XIL(0x55556326ee03)) at ../../src/eval.c:419 #50 0x00005555557862c9 in eval_sub (form=) at ../../src/eval.c:2541 #51 0x0000555555787ec0 in Fprogn (body=) at ../../src/eval.c:439 #52 funcall_lambda (fun=, nargs=, arg_vector=) at ../../src/eval.c:3342 #53 0x00005555557885be in Ffuncall (nargs=4, args=0x7fffffffb640) at ../../src/eval.c:3085 #54 0x0000555555728665 in Fall_completions (string=, collection=, predicate=XIL(0), hide_spaces=XIL(0)) at ../../src/minibuf.c:1875 #55 0x0000555555786425 in eval_sub (form=) at ../../src/eval.c:2600 #56 0x0000555555787ec0 in Fprogn (body=) at ../../src/eval.c:439 #57 funcall_lambda (fun=, nargs=, arg_vector=) at ../../src/eval.c:3342 #58 0x00005555557dd62e in exec_byte_code (fun=XIL(0), args_template=1, nargs=4, args=0x7fffeddff168) at ../../src/bytecode.c:814 #59 0x00005555557885be in Ffuncall (nargs=2, args=0x7fffffffb960) at ../../src/eval.c:3085 #60 0x0000555555796b0b in mapcar1 (leni=2, vals=vals@entry=0x0, fn=fn@entry=XIL(0x555568d1434d), seq=seq@entry=XIL(0x55556326d653)) at ../../src/fns.c:3366 #61 0x0000555555796e04 in Fmapc (function=XIL(0x555568d1434d), sequence=XIL(0x55556326d653)) at ../../src/fns.c:3503 #62 0x00005555557dd75f in exec_byte_code (fun=XIL(0), args_template=1, nargs=2, args=0x7fffeddff0e0) at ../../src/lisp.h:2255 #63 0x00005555557885be in Ffuncall (nargs=3, args=0x7fffffffbbe0) at ../../src/eval.c:3085 #64 0x00007fffef005f64 in F636f6d706c6574696f6e2d2d6e74682d636f6d706c6574696f6e_completion__nth_completion_0 () at /usr/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-b90a846c/preloaded/minibuffer-1b0f548b-aed76e44.eln #65 0x00005555557885be in Ffuncall (nargs=7, args=0x7fffffffbd10) at ../../src/eval.c:3085 #66 0x00007fffef0063a0 in F636f6d706c6574696f6e2d616c6c2d636f6d706c6574696f6e73_completion_all_completions_0 () at /usr/bin/../lib/emacs/31.0.50/native-lisp/31.0.50-b90a846c/preloaded/minibuffer-1b0f548b-aed76e44.eln #67 0x00005555557885be in Ffuncall (nargs=nargs@entry=6, args=0x7fffffffbdc0) at ../../src/eval.c:3085 #68 0x00005555557896a0 in Fapply (nargs=2, args=0x7fffeddff048) at ../../src/eval.c:2757 #69 0x00005555557dd75f in exec_byte_code (fun=XIL(0), args_template=1, nargs=2, args=0x7fffeddff048) at ../../src/lisp.h:2255 #70 0x00005555557885be in Ffuncall (nargs=6, args=0x7fffffffc0b0) at ../../src/eval.c:3085 #71 0x00007fffc4068b53 in F636f6d706c6574696f6e2d707265766965772d2d7472792d7461626c65_completion_preview__try_table_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/31.0.50-b90a846c/completion-preview-b8bd3a06-2fbe13ad.eln #72 0x00005555557885be in Ffuncall (nargs=5, args=0x7fffffffc1a0) at ../../src/eval.c:3085 #73 0x00007fffc40690f9 in F636f6d706c6574696f6e2d707265766965772d2d636170662d77726170706572_completion_preview__capf_wrapper_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/31.0.50-b90a846c/completion-preview-b8bd3a06-2fbe13ad.eln #74 0x00005555557885be in Ffuncall (nargs=2, args=args@entry=0x7fffffffc2c0) at ../../src/eval.c:3085 #75 0x000055555578bdb1 in run_hook_wrapped_funcall (nargs=, args=0x7fffffffc2c0) at ../../src/eval.c:2864 #76 0x0000555555784b72 in run_hook_with_args (nargs=2, args=0x7fffffffc2c0, funcall=0x55555578bd90 ) at ../../src/eval.c:2945 #77 0x00007fffc4069330 in F636f6d706c6574696f6e2d707265766965772d2d757064617465_completion_preview__update_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/31.0.50-b90a846c/completion-preview-b8bd3a06-2fbe13ad.eln #78 0x00005555557885be in Ffuncall (nargs=1, args=0x7fffffffc4a0) at ../../src/eval.c:3085 #79 0x00007fffc4069a0f in F636f6d706c6574696f6e2d707265766965772d2d7472792d757064617465_completion_preview__try_update_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/31.0.50-b90a846c/completion-preview-b8bd3a06-2fbe13ad.eln #80 0x00005555557885be in Ffuncall (nargs=1, args=0x7fffffffc620) at ../../src/eval.c:3085 #81 0x00007fffc4069ff2 in F636f6d706c6574696f6e2d707265766965772d2d73686f77_completion_preview__show_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/31.0.50-b90a846c/completion-preview-b8bd3a06-2fbe13ad.eln #82 0x00005555557885be in Ffuncall (nargs=1, args=0x7fffffffc6f0) at ../../src/eval.c:3085 #83 0x00007fffc406a13d in F636f6d706c6574696f6e2d707265766965772d2d706f73742d636f6d6d616e64_completion_preview__post_command_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/31.0.50-b90a846c/completion-preview-b8bd3a06-2fbe13ad.eln #84 0x00005555557885be in Ffuncall (nargs=1, args=0x7fffffffc7b8) at ../../src/eval.c:3085 #85 0x00005555558579f1 in internal_condition_case_n.constprop.0 (bfun=bfun@entry=0x5555556e6ef0 , nargs=nargs@entry=2, args=args@entry=0x7fffffffc7b0, hfun=hfun@entry=0x5555556e7240 , handlers=XIL(0x30)) at ../../src/eval.c:1693 #86 0x00005555556e7777 in safe_run_hook_funcall (nargs=2, args=0x7fffffffc870) at ../../src/keyboard.c:1944 #87 0x0000555555784b72 in run_hook_with_args (nargs=2, args=0x7fffffffc870, funcall=0x5555556e76a0 ) at ../../src/eval.c:2945 #88 0x00005555558692db in safe_run_hooks_maybe_narrowed.isra.0 (hook=hook@entry=XIL(0xf1e0), w=) at ../../src/keyboard.c:1982 #89 0x00005555556eb35c in command_loop_1 () at ../../src/keyboard.c:1568 #90 0x00005555557839f7 in internal_condition_case (bfun=0x5555556eaee0 , handlers=, hfun=0x5555556e8af0 ) at ../../src/eval.c:1613 #91 0x00005555556e709e in command_loop_2 (handlers=handlers@entry=XIL(0x90)) at ../../src/keyboard.c:1168 #92 0x000055555578393a in internal_catch (tag=, func=0x5555556e7070 , arg=XIL(0x90)) at ../../src/eval.c:1292 #93 0x00005555556eaea3 in command_loop () at ../../src/keyboard.c:1146 #94 0x0000555555868f8b in recursive_edit_1.isra.0 () at ../../src/keyboard.c:754 #95 0x00005555556f04d1 in Frecursive_edit () at ../../src/keyboard.c:837 #96 0x00005555555b3318 in main (argc=, argv=0x7fffffffce78) at ../../src/emacs.c:2624 ```

The propname in the final line refers to the event-symbol-element-mask symbol, as can also be seen by going to the files and lines that the backtrace points to.

Lisp backtrace from gdb:

Lisp backtrace (completion-all-completions ... all-completions ... lsp-request-while-no-input ... sit-for) - "sit-for" (0xffffa520) - "catch" (0xffffa610) - "while" (0xffffa700) - "progn" (0xffffa7d0) - "unwind-protect" (0xffffa8a0) - "let*" (0xffffa9d0) - "if" (0xffffaa80) - "lsp-request-while-no-input" (0xffffaba0) - "let*" (0xffffad60) - "cond" (0xffffae40) - "let" (0xffffaf80) - "catch" (0xffffb080) - "let" (0xffffb1b0) - 0x69808d70 PVEC_CLOSURE - "funcall" (0xffffb300) - "complete-with-action" (0xffffb3d0) - "cond" (0xffffb4b0) - 0x69809dc0 PVEC_CLOSURE - "all-completions" (0xffffb6d0) - "lsp-completion-passthrough-all-completions" (0xeddff168) - 0x68d14318 PVEC_CLOSURE - 0x68d14348 PVEC_CLOSURE - "mapc" (0xeddff0e0) - "seq-do" (0xeddff090) - "seq-some" (0xffffbbe8) - "completion--nth-completion" (0xffffbd18) - 0xef80c2c0 PVEC_SUBR - "apply" (0xeddff048) - "completion-all-completions" (0xffffc0b8) - "completion-preview--try-table" (0xffffc1a8) - "completion-preview--capf-wrapper" (0xffffc2c8) - "completion-preview--update" (0xffffc4a8) - "completion-preview--try-update" (0xffffc628) - "completion-preview--show" (0xffffc6f8) - "completion-preview--post-command" (0xffffc7c0)

So the crash, at least in my case, seems to be, for some reason, happening in lsp-request-while-no-input.

Also, notably, this is triggered by completion-preview-mode (an Emacs 30 feature) and not by Company, suggesting that Company is not the problem here.


After going back to Emacs 29.4 I am still able to reproduce it under gdb. Though I wasn't able to trigger it in another attempt when I turned off optimizations (-O0 -g3). My guess is because this is a race condition that is harder to trigger when the performance is worse.

For the 29.4 crash, the error is

Thread 1 "emacs" received signal SIGSEGV, Segmentation fault.
Fget (symbol=<optimized out>, propname=XIL(0x6a20)) at ../../src/fns.c:2516
2516    DEFUN ("get", Fget, Sget, 2, 2, 0,

C backtrace:

C backtrace (with some spurious file not found errors sprinkled within, they can probably be ignored) ```shellsession (gdb) bt #0 Fget (symbol=, propname=XIL(0x6a20)) at ../../src/fns.c:2516 #1 0x00005555556f448f in parse_modifiers (symbol=XIL(0x55555685e590)) at ../../src/keyboard.c:6897 #2 parse_modifiers (symbol=XIL(0x55555685e590)) at ../../src/keyboard.c:6888 #3 0x0000555555703ea8 in reorder_modifiers (symbol=XIL(0x55555685e590)) at ../../src/keyboard.c:7028 #4 access_keymap_1 (map=XIL(0x7fffefe09fcb), idx=XIL(0x55555685e590), t_ok=false, noinherit=false, autoload=true) at ../../src/keymap.c:342 #5 0x00005555556f9c97 in access_keymap (noinherit=false, autoload=true, map=, idx=, t_ok=false) at ../../src/keymap.c:496 #6 read_char (commandflag=0, map=XIL(0), prev_event=XIL(0), used_mouse_menu=0x0, end_time=0x7fffffffb5c0) at ../../src/keyboard.c:3018 #7 0x00005555557b9f61 in read_filtered_event (no_switch_frame=false, ascii_required=false, error_nonascii=false, input_method=, seconds=XIL(0x555559982d67)) at ../../src/lread.c:702 #8 0x00007fffef4433d7 in F7369742d666f72_sit_for_0 () at /usr/bin/../lib/emacs/29.4/native-lisp/29.4-0af1ed90/preloaded/subr-13adf6a6-bfb9f448.eln #9 0x00005555557df1be in exec_byte_code (fun=XIL(0), args_template=1, nargs=1, args=0x7fffedfff3f0) at ../../src/bytecode.c:809 #10 0x0000555555789eae in Ffuncall (nargs=4, args=0x7fffffffb850) at ../../src/eval.c:2999 #11 0x000055555572cc4f in call3 (fn=XIL(0x555576c25405), arg1=, arg2=XIL(0), arg3=XIL(0x30)) at ../../src/lisp.h:3262 #12 Fall_completions (string=, collection=XIL(0x555576c25405), predicate=XIL(0), hide_spaces=XIL(0)) at ../../src/minibuf.c:1869 #13 0x00005555557df1be in exec_byte_code (fun=XIL(0), args_template=1, nargs=3, args=0x7fffedfff278) at ../../src/bytecode.c:809 warning: BFD: reopening /tmp/freefn-2b656d6163732d6c6973702d686967686c696768742d766172732d616e642d6661636573_emacs_lisp_highlight_vars_and_faces_0wlu2fe.eln: 沒有此一檔案或目錄 warning: Can't read data for section '.eh_frame' in file '/tmp/freefn-2b656d6163732d6c6973702d686967686c696768742d766172732d616e642d6661636573_emacs_lisp_highlight_vars_and_faces_0wlu2fe.eln' #14 0x0000555555789eae in Ffuncall (nargs=2, args=0x7fffffffba90) at ../../src/eval.c:2999 #15 0x00007fffef3e28f2 in F636f6d706c6574696f6e2d2d736f6d65_completion__some_0 () at /usr/bin/../lib/emacs/29.4/native-lisp/29.4-0af1ed90/preloaded/minibuffer-1b0f548b-25462d74.eln #16 0x0000555555789eae in Ffuncall (nargs=3, args=0x7fffffffbb90) at ../../src/eval.c:2999 #17 0x00007fffef3e7f34 in F636f6d706c6574696f6e2d2d6e74682d636f6d706c6574696f6e_completion__nth_completion_0 () at /usr/bin/../lib/emacs/29.4/native-lisp/29.4-0af1ed90/preloaded/minibuffer-1b0f548b-25462d74.eln #18 0x0000555555789eae in Ffuncall (nargs=7, args=0x7fffffffbcc0) at ../../src/eval.c:2999 #19 0x00007fffef3e834e in F636f6d706c6574696f6e2d616c6c2d636f6d706c6574696f6e73_completion_all_completions_0 () at /usr/bin/../lib/emacs/29.4/native-lisp/29.4-0af1ed90/preloaded/minibuffer-1b0f548b-25462d74.eln #20 0x0000555555789eae in Ffuncall (nargs=nargs@entry=6, args=0x7fffffffbd40) at ../../src/eval.c:2999 #21 0x000055555578ad80 in Fapply (nargs=2, args=0x7fffedfff1d0) at ../../src/eval.c:2670 #22 0x00005555557df1be in exec_byte_code (fun=XIL(0), args_template=1, nargs=2, args=0x7fffedfff1d0) at ../../src/bytecode.c:809 #23 0x0000555555789eae in Ffuncall (nargs=3, args=0x7fffffffc000) at ../../src/eval.c:2999 #24 0x00007fffc223af0c in F636f6d70616e792d2d6d756c74692d6261636b656e642d616461707465722d63616e64696461--Type for more, q to quit, c to continue without paging--c 746573_company__multi_backend_adapter_candidates_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/29.4-0af1ed90/company-ce1324ef-b64d4357.eln #25 0x0000555555789eae in Ffuncall (nargs=5, args=0x7fffffffc170) at ../../src/eval.c:2999 #26 0x00007fffc2239fbc in F636f6d70616e792d2d6d756c74692d6261636b656e642d61646170746572_company__multi_backend_adapter_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/29.4-0af1ed90/company-ce1324ef-b64d4357.eln #27 0x0000555555789eae in Ffuncall (nargs=nargs@entry=4, args=0x7fffffffc210) at ../../src/eval.c:2999 #28 0x000055555578ad80 in Fapply (nargs=3, args=0x7fffffffc310) at ../../src/eval.c:2670 #29 0x0000555555789eae in Ffuncall (nargs=4, args=0x7fffffffc308) at ../../src/eval.c:2999 #30 0x00007fffc22398ed in F636f6d70616e792d63616c6c2d6261636b656e642d726177_company_call_backend_raw_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/29.4-0af1ed90/company-ce1324ef-b64d4357.eln #31 0x0000555555789eae in Ffuncall (nargs=3, args=0x7fffffffc3c0) at ../../src/eval.c:2999 #32 0x00007fffc223d7f2 in F636f6d70616e792d2d66657463682d63616e64696461746573_company__fetch_candidates_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/29.4-0af1ed90/company-ce1324ef-b64d4357.eln #33 0x0000555555789eae in Ffuncall (nargs=2, args=0x7fffffffc4c8) at ../../src/eval.c:2999 #34 0x00007fffc223d1ba in F636f6d70616e792d63616c63756c6174652d63616e64696461746573_company_calculate_candidates_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/29.4-0af1ed90/company-ce1324ef-b64d4357.eln #35 0x0000555555789eae in Ffuncall (nargs=3, args=0x7fffffffc590) at ../../src/eval.c:2999 #36 0x00007fffc2241e8a in F636f6d70616e792d2d636f6e74696e7565_company__continue_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/29.4-0af1ed90/company-ce1324ef-b64d4357.eln #37 0x0000555555789eae in Ffuncall (nargs=1, args=0x7fffffffc638) at ../../src/eval.c:2999 #38 0x00007fffc224295d in F636f6d70616e792d2d706572666f726d_company__perform_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/29.4-0af1ed90/company-ce1324ef-b64d4357.eln #39 0x0000555555789eae in Ffuncall (nargs=1, args=0x7fffffffc6d0) at ../../src/eval.c:2999 #40 0x00007fffc22438d6 in F636f6d70616e792d706f73742d636f6d6d616e64_company_post_command_0 () at /home/kisaragi-hiu/.config/emacs/.local/cache/eln/29.4-0af1ed90/company-ce1324ef-b64d4357.eln #41 0x0000555555789eae in Ffuncall (nargs=1, args=0x7fffffffc7b8) at ../../src/eval.c:2999 #42 0x0000555555859f01 in internal_condition_case_n.constprop.0 (bfun=bfun@entry=0x5555556ebb00 , nargs=nargs@entry=2, args=args@entry=0x7fffffffc7b0, hfun=hfun@entry=0x5555556ec1b0 , handlers=XIL(0x30)) at ../../src/eval.c:1558 #43 0x00005555556ec77e in safe_run_hook_funcall (nargs=2, args=0x7fffffffc890) at ../../src/keyboard.c:1893 #44 0x0000555555788c1c in run_hook_with_args (nargs=2, args=0x7fffffffc890, funcall=0x5555556ec6a0 ) at ../../src/eval.c:2858 #45 0x000055555586a6db in safe_run_hooks_maybe_narrowed.isra.0 (hook=hook@entry=XIL(0xd290), w=) at ../../src/keyboard.c:1931 #46 0x00005555556ee908 in command_loop_1 () at ../../src/keyboard.c:1518 #47 0x0000555555787907 in internal_condition_case (bfun=0x5555556ee430 , handlers=, hfun=0x5555556edc30 ) at ../../src/eval.c:1474 #48 0x00005555556ec06e in command_loop_2 (handlers=handlers@entry=XIL(0x90)) at ../../src/keyboard.c:1133 #49 0x000055555578784a in internal_catch (tag=, func=0x5555556ec040 , arg=XIL(0x90)) at ../../src/eval.c:1197 #50 0x00005555556ee3f3 in command_loop () at ../../src/keyboard.c:1111 #51 0x000055555586a57b in recursive_edit_1.isra.0 () at ../../src/keyboard.c:720 #52 0x00005555556f0411 in Frecursive_edit () at ../../src/keyboard.c:803 #53 0x00005555555b358d in main (argc=1, argv=0x7fffffffce68) at ../../src/emacs.c:2521 ```

Lisp backtrace:

Lisp backtrace: company-post-command ... completion-all-completions ... all-completions ... lsp-request-while-no-input → sit-for - "sit-for" (0xedfff3f0) - "lsp-request-while-no-input" (0xedfff328) - 0x76c253a0 PVEC_COMPILED - 0x76c25400 PVEC_COMPILED - "all-completions" (0xedfff278) - "lsp-completion-passthrough-all-completions" (0xedfff210) - 0x70d99030 PVEC_COMPILED - "completion--some" (0xffffbb98) - "completion--nth-completion" (0xffffbcc8) - 0xef95a6b8 PVEC_SUBR - "apply" (0xedfff1d0) - "completion-all-completions" (0xedfff170) - "company-capf--candidates-1" (0xedfff0c0) - "company-capf--candidates" (0xedfff050) - "company-capf" (0xffffc008) - "company--multi-backend-adapter-candidates" (0xffffc178) - "company--multi-backend-adapter" (0xffffc218) - "apply" (0xffffc310) - "company-call-backend-raw" (0xffffc3c8) - "company--fetch-candidates" (0xffffc4d0) - "company-calculate-candidates" (0xffffc598) - "company--continue" (0xffffc640) - "company--perform" (0xffffc6d8) - "company-post-command" (0xffffc7c0)

So on Emacs 29.4 this is happening at the same place: in lsp-request-while-no-input, in sit-for.

programmador commented 4 days ago

Same thing with Spacemacs + intelephense(PHP) with emacs 29.4. It started to happen at some moment about few months ago - maybe when emacs itself updated, I don't know. When autocomplete popup should appear emacs hangs for few seconds and then crashes this way:

Fatal error 11: Segmentation fault
Backtrace:
emacs(+0x192c0b) [0x5c17eb35bc0b]
emacs(+0x2396f) [0x5c17eb1ec96f]
emacs(+0x2477a) [0x5c17eb1ed77a]
emacs(+0x2d91e5) [0x5c17eb4a21e5]
/usr/lib/libc.so.6(+0x3d1d0) [0x73d3a9e5c1d0]
emacs(+0x2275db) [0x5c17eb3f05db]
emacs(+0x17af41) [0x5c17eb343f41]
emacs(+0x18af78) [0x5c17eb353f78]
emacs(+0x18087b) [0x5c17eb34987b]
emacs(+0x245a92) [0x5c17eb40ea92]
emacs(+0x26432c) [0x5c17eb42d32c]
emacs(+0x21c3ed) [0x5c17eb3e53ed]
emacs(+0x1b4c82) [0x5c17eb37dc82]
emacs(+0x26432c) [0x5c17eb42d32c]
emacs(+0x21c3ed) [0x5c17eb3e53ed]
emacs(+0x21cd20) [0x5c17eb3e5d20]
emacs(+0x26432c) [0x5c17eb42d32c]
emacs(+0x21c3ed) [0x5c17eb3e53ed]
emacs(+0x2dc63e) [0x5c17eb4a563e]
emacs(+0x172b92) [0x5c17eb33bb92]
emacs(+0x219aec) [0x5c17eb3e2aec]
emacs(+0x2f096d) [0x5c17eb4b996d]
emacs(+0x175087) [0x5c17eb33e087]
emacs(+0x20acce) [0x5c17eb3d3cce]
emacs(+0x17240e) [0x5c17eb33b40e]
emacs(+0x20ac28) [0x5c17eb3d3c28]
emacs(+0x174b8b) [0x5c17eb33db8b]
emacs(+0x2f07ff) [0x5c17eb4b97ff]
emacs(+0x176ccd) [0x5c17eb33fccd]
emacs(+0x34d9d) [0x5c17eb1fdd9d]
/usr/lib/libc.so.6(+0x25e08) [0x73d3a9e44e08]
/usr/lib/libc.so.6(__libc_start_main+0x8c) [0x73d3a9e44ecc]
emacs(+0x362f5) [0x5c17eb1ff2f5]
fish: Job 1, 'emacs' terminated by signal SIGSEGV (Address boundary error)

It happens quite rarely actually. Most of time I'm just working without any issues. It took me some time to catch it (launching emacs from command line and working until it crashes).

When I open emacs again, open the same project and do the same things which I was doing when it crashed (autocompleting the same item) - it just does it without crashing. So it's related rather to specific moment than to specific project code state.

I'm not really sure but it seems to happen more often while working on a laptop in powersaving cpu profile while the A/C adapter is detached - so it may be some timeout related issue. But again: I'm really not sure about this thing, it's very hard to gather reliable statistics because as I mentioned above in my case the crashes are generally quite rare.

kisaragi-hiu commented 4 days ago

Unfortunately Gdb info does not seem useful to me.

You need to run gdb from the src directory of a local Emacs source code checkout (to load src/.gdbinit), and also probably build Emacs from the local checkout, to get a useful backtrace. etc/DEBUG has some useful info as well and is worth a read.

quentin-ag commented 4 days ago

Hi! I have face a similar issue with vanilla Emacs 29.4 on Arch Linux. I am using corfu, not company-mode, but I use company backends with cape-company-to-capf. The crashes are also seemingly random, but fairly frequent (perhaps every one or two hours).

I have found two bug reports in the GNU mailing lists that could be possibly be related:

As a temporary workaround, I have downgraded Emacs to 29.3. Since then, no crash has happened.

I hope this information can help others.

real-or-random commented 3 days ago

Emacs bug#71744

This looks right, and this bug is fixed in emacs 30 which will be released soon.

kisaragi-hiu commented 3 hours ago

I tried out the Emacs 30 pretest, which includes the patch, and haven't encountered the crash once in several hours. I think this issue is fixed now (and it seems to have turned out to solely be an upstream issue).

(The corresponding commit on upstream master is a967efdd.)