minad / corfu

:desert_island: corfu.el - COmpletion in Region FUnction
GNU General Public License v3.0
1.11k stars 43 forks source link

Corfu segmentation faults if prompted to complete while LSP server is indexing #461

Closed alexispurslane closed 4 months ago

alexispurslane commented 4 months ago

Description

If corfu enabled is prompted to start autocompletion (by typing the first 3 letters of a word in my case) while an eglot LSP server is staring up, you get a segmentation fault.

Steps to reproduce

  1. Open a file with a mode associated with it that has a language server
  2. M-x eglot
  3. Before the server has finished indexing and can provide completions, prompt corfu to do an autocompletion
  4. Enjoy :yum:

Debug information

Here's the backtrace from the core dump:

Fatal error 11: Segmentation fault
Backtrace:
emacs(emacs_backtrace+0x5a)[0x595c1a]
emacs(terminate_due_to_signal+0x9f)[0x467885]
emacs[0x468623]
emacs[0x70bae4]
/lib64/libc.so.6(+0x40750)[0x7f153d9e3750]
emacs(parse_modifiers+0x12c)[0x57a06c]
emacs[0x590ad8]
emacs(read_char+0x212a)[0x57f7ea]
emacs[0x648f3a]
/usr/bin/../lib64/emacs/29.3/native-lisp/29.3-f9fbfec9/preloaded/subr-13adf6a6-bfb9f448.eln(F7369742d666f72_sit_for_0+0x19f)[0x7f1536c1b2ff]
emacs(Ffuncall+0xfd)[0x62148d]
/usr/lib64/emacs/29.3/native-lisp/29.3-f9fbfec9/jsonrpc-e62a9c36-62ae7160.eln(F6a736f6e7270632d72657175657374_jsonrpc_request_0+0xa14)[0x7f152409e2c4]
emacs(Ffuncall+0xfd)[0x62148d]
emacs(Fapply+0x1b0)[0x621b90]
emacs(exec_byte_code+0x54c)[0x66b8bc]
emacs(Ffuncall+0xfd)[0x62148d]
emacs(Fall_completions+0x372)[0x5b6122]
/usr/bin/../lib64/emacs/29.3/native-lisp/29.3-f9fbfec9/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d70636d2d2d616c6c2d636f6d706c6574696f6e73_completion_pcm__all_completions_0+0x1a7)[0x7f1536bbda67]
emacs(Ffuncall+0xfd)[0x62148d]
/usr/bin/../lib64/emacs/29.3/native-lisp/29.3-f9fbfec9/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d737562737472696e672d2d616c6c2d636f6d706c6574696f6e73_completion_substring__all_completions_0+0x1d6)[0x7f1536bc0f86]
emacs(Ffuncall+0xfd)[0x62148d]
/usr/bin/../lib64/emacs/29.3/native-lisp/29.3-f9fbfec9/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d666c65782d616c6c2d636f6d706c6574696f6e73_completion_flex_all_completions_0+0xb6)[0x7f1536bc1a16]
emacs(Ffuncall+0xfd)[0x62148d]
emacs(Fapply+0x1b0)[0x621b90]
emacs(exec_byte_code+0x54c)[0x66b8bc]
emacs(Ffuncall+0xfd)[0x62148d]
/usr/bin/../lib64/emacs/29.3/native-lisp/29.3-f9fbfec9/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d2d736f6d65_completion__some_0+0x1e2)[0x7f1536baa852]
emacs(Ffuncall+0xfd)[0x62148d]
/usr/bin/../lib64/emacs/29.3/native-lisp/29.3-f9fbfec9/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d2d6e74682d636f6d706c6574696f6e_completion__nth_completion_0+0x2d4)[0x7f1536baf914]
emacs(Ffuncall+0xfd)[0x62148d]
/usr/bin/../lib64/emacs/29.3/native-lisp/29.3-f9fbfec9/preloaded/minibuffer-1b0f548b-25462d74.eln(F636f6d706c6574696f6e2d616c6c2d636f6d706c6574696f6e73_completion_all_completions_0+0x50)[0x7f1536bafcd0]
emacs(Ffuncall+0xfd)[0x62148d]
emacs(Fapply+0x1b0)[0x621b90]
emacs(exec_byte_code+0x54c)[0x66b8bc]
emacs(Ffuncall+0xfd)[0x62148d]
emacs(Fapply+0x1b0)[0x621b90]
/var/home/alexispurslane/.emacs.d/eln-cache/29.3-f9fbfec9/corfu-4ecf6dfc-d30fc894.eln(F636f7266752d2d66696c7465722d636f6d706c6574696f6e73_corfu__filter_completions_0+0x199)[0x7f1524616be9]
emacs(Ffuncall+0xfd)[0x62148d]
/var/home/alexispurslane/.emacs.d/eln-cache/29.3-f9fbfec9/corfu-4ecf6dfc-d30fc894.eln(F636f7266752d2d7265636f6d70757465_corfu__recompute_0+0x29e)[0x7f1524617b9e]
emacs(Ffuncall+0xfd)[0x62148d]
/var/home/alexispurslane/.emacs.d/eln-cache/29.3-f9fbfec9/corfu-4ecf6dfc-d30fc894.eln(F636f7266752d2d757064617465_corfu__update_0+0x755)[0x7f1524618e25]
...
Segmentation fault: oops, process 'emacs' core dumped

Here's my Emacs info:

GNU Emacs 29.3 (build 1, x86_64-redhat-linux-gnu, GTK+ Version
 5.24.41, cairo version 1.18.0) of 2024-04-18

Config

Here's my corfu and orderless configuration:

;; Optionally use the `orderless' completion style for proper fuzzy searching
    ;; in vertico
    (use-package orderless
        :after vertico
        :init
    (setq completion-styles '(orderless basic)
          completion-category-defaults nil
              completion-category-overrides '((file (styles partial-completion)))))

(use-package corfu
        ;; Optional customizations
        :custom
        (corfu-cycle t)                ;; Enable cycling for `corfu-next/previous'
        (corfu-auto t)                 ;; Enable auto completion
        (corfu-separator ?\s)          ;; Orderless field separator
        (corfu-quit-no-match 'separator)
        (corfu-auto-delay 0.12)
        (corfu-auto-prefix 3)
        (corfu-popupinfo-delay 0.22)
        (corfu-popupinfo-direction 'right)
        :config
        (global-corfu-mode)
        (defun corfu-enable-in-minibuffer ()
            "Enable Corfu in the minibuffer."
            (when (local-variable-p 'completion-at-point-functions)
                (setq-local corfu-echo-delay nil ;; Disable automatic echo and popup
                            corfu-popupinfo-delay nil)
                (corfu-mode 1)))
        (add-hook 'minibuffer-setup-hook #'corfu-enable-in-minibuffer)

        (defun corfu-popupinfo-start ()
            (require 'corfu-popupinfo)
            (set-face-attribute 'corfu-popupinfo nil :inherit 'variable-pitch)
            (corfu-popupinfo-mode))
        (add-hook 'corfu-mode-hook #'corfu-popupinfo-start))

(use-package nerd-icons
        :if (display-graphic-p)
        :custom (nerd-icons-font-family "Symbols Nerd Font Mono"))

    ;; Integrate them with corfu
    (use-package nerd-icons-corfu
        :after (corfu nerd-icons)
        :config (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))

I was able to repro this bug with just this in my config, though:

(use-package corfu
        ;; Optional customizations
        :custom
        (corfu-cycle t)                ;; Enable cycling for `corfu-next/previous'
        (corfu-auto t)                 ;; Enable auto completion
        (corfu-separator ?\s)          ;; Orderless field separator
        (corfu-quit-no-match 'separator)
        (corfu-auto-delay 0.12)
        (corfu-auto-prefix 3)
        (corfu-popupinfo-delay 0.22)
        (corfu-popupinfo-direction 'right)
        :config
        (global-corfu-mode)
        (defun corfu-enable-in-minibuffer ()
            "Enable Corfu in the minibuffer."
            (when (local-variable-p 'completion-at-point-functions)
                (setq-local corfu-echo-delay nil ;; Disable automatic echo and popup
                            corfu-popupinfo-delay nil)
                (corfu-mode 1)))
        (add-hook 'minibuffer-setup-hook #'corfu-enable-in-minibuffer)

        (defun corfu-popupinfo-start ()
            (require 'corfu-popupinfo)
            (set-face-attribute 'corfu-popupinfo nil :inherit 'variable-pitch)
            (corfu-popupinfo-mode))
        (add-hook 'corfu-mode-hook #'corfu-popupinfo-start))
minad commented 4 months ago

Thanks for finding this. Emacs crashes should be reported upstream, via M-x report-emacs-bug.

alexispurslane commented 4 months ago

Thanks for finding this. Emacs crashes should be reported upstream, via M-x report-emacs-bug.

Ah, ok. I thought since it was (at least seemingly) caused by corfu, it would make sense to post it here, but since corfu is written in elisp, and elisp should never crash emacs, it makes sense this is an emacs bug.

sdubinsky commented 3 months ago

@alexispurslane I am encountering the same bug - did you report it upstream anywhere? I'd like to follow it if so.

sdubinsky commented 3 months ago

Found it logged here: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71073 If anyone can reproduce or has more info, that's where to go.

idhx commented 1 month ago

A similar (the same?) bug has also been reported here: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71744. It looks like the root cause has been identified and a patch is in the works.