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

kak-lsp crashes with bogus pointer (double free?) on OpenBSD #388

Closed
daeluk opened this issue Aug 20, 2020 · 4 comments
Closed

kak-lsp crashes with bogus pointer (double free?) on OpenBSD #388

daeluk opened this issue Aug 20, 2020 · 4 comments

Comments

@daeluk
Copy link

daeluk commented Aug 20, 2020

Hi there :)

I've been trying to get kak-lsp working on my maching running OpenBSD 6.7-stable, but it keeps crashing unfortunately. I am not very familiar with rust so I couldn't really dig into the code. I couldn't find anything similar happening in the issues so far so I thought I'd open a new one.

I had the chance of testing kak-lsp on a Mac running OS X at work, where I didn't experience any of these problems.

System specs:

  • OS: OpenBSD 6.7-stable
  • kak-lsp version: 8.0.0-snapshot (installed manually with cargo)
  • kakoune version: v2020.08.04
  • cargo version: 1.42.0
  • default kak-lsp configuration copied to $XDG_CONFIG_HOME/kak-lsp/kak-lsp.toml

I've only tried using kak-lsp with go. The lsp client crashes the moment I open a go file in kakoune.

Relevant kakrc part:

eval %sh{kak-lsp -c --kakoune "$XDG_CONFIG_HOME"/kak-lsp/kak-lsp.toml -s "$kak_session"}
set-option global lsp_completion_trigger "execute-keys 'h<a-h><a-k>\S[^\h\n,=;*(){}\[\]]\z<ret>'"
set-option global lsp_diagnostic_line_error_sign "!"
set-option global lsp_diagnostic_line_warning_sign "?"
hook global WinSetOption filetype=go %{
    map window user "l" ": enter-user-mode lsp<ret>" -docstring "LSP mode"
    lsp-enable-window
    lsp-auto-hover-enable
    lsp-auto-hover-insert-mode-disable
    set-option window lsp_hover_anchor true
    set-face window DiagnosticError default+u
    set-face window DiagnosticWarning default+u
}
hook global KakEnd .* lsp-exit

output when running kak-lsp -s foobar -vvv in a seperate terminal:

Aug 19 12:44:41.836 INFO Starting main event loop, module: kak_lsp::session:29
Aug 19 12:44:52.321 DEBG From editor: 
session  = "foobar"
client   = ""
buffile  = "/home/daeluk/src/go/src/gitlab.com/daeluk/cryptopals/set1/hex2b64.go"
filetype = "go"
version  = 1
method   = "workspace/didChangeConfiguration"
[params.settings]
, module: kak_lsp::editor_transport:125
Aug 19 12:44:52.322 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_GO, module: kak_lsp::project_root:46
Aug 19 12:44:52.325 DEBG Routing editor request to Route { session: "foobar", language: "go", root: "/home/daeluk/src/go/src/gitlab.com/daeluk/cryptopals" }, module: kak_lsp::session:95
Aug 19 12:44:52.325 DEBG Spawning a new controller for Route { session: "foobar", language: "go", root: "/home/daeluk/src/go/src/gitlab.com/daeluk/cryptopals" }, module: kak_lsp::session:117
Aug 19 12:44:52.325 INFO Starting Language server `gopls `, module: kak_lsp::language_server_transport:21
Aug 19 12:44:52.326 DEBG From editor: 
session  = "foobar"
client   = ""
buffile  = "/home/daeluk/src/go/src/gitlab.com/daeluk/cryptopals/set1/hex2b64.go"
filetype = "go"
version  = 1
method   = "textDocument/didOpen"
[params]
draft    = """
<a bunch of go code>
"""
, module: kak_lsp::editor_transport:125
Aug 19 12:44:52.327 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_GO, module: kak_lsp::project_root:46
Aug 19 12:44:52.328 DEBG Routing editor request to Route { session: "foobar", language: "go", root: "/home/daeluk/src/go/src/gitlab.com/daeluk/cryptopals" }, module: kak_lsp::session:95
Aug 19 12:44:52.331 DEBG To editor `foobar`: lsp-get-server-initialization-options 'daeluk/ab971890759b4664', module: kak_lsp::editor_transport:85
Aug 19 12:44:52.350 DEBG lsp_server_initialization_options:
kak-lsp(64896) in free(): bogus pointer (double free?) 0x8a2098bc256, 
module: Abort trap 

Output in *debug* kakoune buffer when running kak-lsp automatically:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "no current exe available (short)" }', src/main.rs:179:15
stack backtrace:
   0:      0x1853165f601 - __register_frame_info
   1:      0x1853139948d - __register_frame_info
   2:      0x1853165f352 - __register_frame_info
   3:      0x18531651bb5 - __register_frame_info
   4:      0x18531651774 - __register_frame_info
   5:      0x1853165122d - __register_frame_info
   6:      0x1853139f61f - __register_frame_info
   7:      0x1853139f715 - __register_frame_info
   8:      0x18531453b3e - __register_frame_info
   9:      0x185314395d6 - __register_frame_info
  10:      0x18531449e83 - __register_frame_info
  11:      0x185312e213b - <unknown>

This last one results in the no current exe available error when calling env::current_exe which is platform dependent. Maybe this causes problems on OpenBSD.

Apart from that I noticed that kak-lsp creates a subdirectory containing a <session> socket and <session>.pid file in its current working directory. This also didn't happen on OS X.

I'd be very greatful for any help with this. I appreciate all the work you've done with this project.
Please let me know if there's anything else I could do or provide.

Kind regards,
d

@daeluk
Copy link
Author

daeluk commented Aug 21, 2020

This last one results in the no current exe available error when calling env::current_exe which is platform dependent. Maybe this causes problems on OpenBSD.

I've found this rust issue which explains that part of the problem.
Calling kak-lsp using its absolute path fixes it.

It still doesn't seem to work correctly, though. I don't get any error output into the *debug* buffer, but the language server does not appear to have been started.

@daeluk
Copy link
Author

daeluk commented Aug 21, 2020

And found this issue regarding the bogus pointer (double free?) error.

Closing this since it appears to be an OpenBSD issue.

Too bad I've got no idea how to fix that :/

@daeluk daeluk closed this as completed Aug 21, 2020
@daeluk
Copy link
Author

daeluk commented Aug 26, 2020

Reopening. Maybe someone can at least point me in the right direction.

Also aquired backtrace of the issue (called with /absolute/path/to/executable/kak-lsp -c $XDG_CONFIG_HOME/kak-lsp/kak-lsp.toml -s foobar -vvv):

#0  thrkill () at /tmp/-:3
#1  0x00000bc8d667ab0e in _libc_abort () at /usr/src/lib/libc/stdlib/abort.c:51
#2  0x00000bc8d65f7ba6 in wrterror (d=Variable "d" is not available.
) at /usr/src/lib/libc/stdlib/malloc.c:300
#3  0x00000bc8d65fad76 in findpool (p=0x0, argpool=0x0, foundpool=0x0, 
    saved_function=0xbc8d6669aea) at /usr/src/lib/libc/stdlib/malloc.c:1355
#4  0x00000bc8d65f7eaa in ofree (argpool=0xbc9971b3c70, p=0xbc9971afbd6, 
    clear=0, check=0, argsz=0) at /usr/src/lib/libc/stdlib/malloc.c:1369
#5  0x00000bc8d65f7deb in free (ptr=0xbc9971afbd6)
    at /usr/src/lib/libc/stdlib/malloc.c:1488
#6  0x00000bc6ac0d0601 in kak_lsp::general::initialize::h7a612941ed047076 ()
   from /home/daeluk/bin/rust/bin/kak-lsp
#7  0x00000bc6ac1a6cf1 in kak_lsp::controller::start::h5683d18c9ce9a5dc ()
   from /home/daeluk/bin/rust/bin/kak-lsp
#8  0x00000bc6ac1a3ec8 in std::sys_common::backtrace::__rust_begin_short_backtrace::h8058649ccab0482c () from /home/daeluk/bin/rust/bin/kak-lsp
#9  0x00000bc6ac2893a8 in core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h9e87c2275c01eac5 () from /home/daeluk/bin/rust/bin/kak-lsp
#10 0x00000bc6ac420c60 in _$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hf0af516d3fedc619 ()
   from /home/daeluk/bin/rust/bin/kak-lsp
#11 0x00000bc6ac41380f in std::sys::unix::thread::Thread::new::thread_start::hf8693208c3ef11c7 () from /home/daeluk/bin/rust/bin/kak-lsp
#12 0x00000bc8c8b77111 in _rthread_start (v=Variable "v" is not available.
) at /usr/src/lib/librthread/rthread.c:96
#13 0x00000bc8d6601d28 in __tfork_thread ()
    at /usr/src/lib/libc/arch/amd64/sys/tfork_thread.S:77
#14 0x0000000000000000 in ?? ()

@daeluk daeluk reopened this Aug 26, 2020
@daeluk
Copy link
Author

daeluk commented Sep 5, 2020

Started investigating again and everything just started working.

I believe the problem had something to do with that <user> subdirectory containing the <session>.pid and <session>-socket files being created in the working directory instead of at /tmp/kak-lsp.

After rebuilding everything seems to be back in place and kak-lsp works nicely.

@daeluk daeluk closed this as completed Sep 5, 2020
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