Olical / conjure

Interactive evaluation for Neovim (Clojure, Fennel, Janet, Racket, Hy, MIT Scheme, Guile, Python and more!)
https://conjure.oli.me.uk
The Unlicense
1.75k stars 109 forks source link

Neovim hangs / freezes on quit if Conjure is installed with Clojure, starting v4.40.0 #481

Closed oryband closed 1 year ago

oryband commented 1 year ago

When quitting vim (for example using :q), the window closes and I'm back to my terminal, but then it hangs and I do not get a prompt. My CPU % spikes to 100% and everything grinds to a halt unless I quickly press Ctrl-C or kill all nvim processes.

Here's a minimal configuration where this reproduces: Note I'm using AstroNvim distribution v3.10.3, and I'm not connecting to any external REPL - just opening a clojure file (could it be it launches a REPL behind the scenes without me knowing?)

# uname -a
Linux roach 5.19.0-38-generic #39-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 17:33:16 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.10
DISTRIB_CODENAME=kinetic
DISTRIB_DESCRIPTION="Ubuntu 22.10"

# snap install nvim
# nvim --version
NVIM v0.8.3
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/build/nvim/parts/nvim/build/build/cmake.config -I/build/nvim/parts/nvim/build/src -I/build/nvim/parts/nvim/build/.deps/usr/include -I/usr/include -I/build/nvim/parts/nvim/build/build/src/nvim/auto -I/build/nvim/parts/nvim/build/build/include
Compiled by root@lcy02-amd64-037

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info
-- # cat $HOME/.config/nvim/init.vim
return {
  plugins = {
    -- The issue reproduces starting from 4.40.0
    { "Olical/conjure", ft = { "clojure" }, version = "4.40.0" },
}
Olical commented 1 year ago

I'm going to need more information to work this one out. As far as I know nobody else is experiencing this. Which version of Neovim are you on and which OS? If anyone else has seen this can I get your version details too, thanks.

Invertisment commented 1 year ago

Also how do you start your REPL? Maybe your REPL stays around and then it doesn't end the NVIM process somehow? Does it exit when you don't start REPL?

oryband commented 1 year ago

@Olical @Invertisment I've updated the initial message with as much information as i could get, also attempting to answer your questions.

oryband commented 1 year ago

Disabling client-on-load configuration resolves the issue. Any idea what's going on?

    { "Olical/conjure",
      ft = { "clojure" },
      version = "4.40.x",
      config = function()
        vim.api.nvim_set_var("conjure#client_on_load", false)
      end 
    },
Olical commented 1 year ago

Do you have babashka installed and up to date?

Olical commented 1 year ago

To me it sounds like the babashka auto started REPL is hanging when being asked to close. Not sure why though 🤔

Olical commented 1 year ago

Docs on that here https://github.com/Olical/conjure/blob/7625ed9afc689888a743492547b0f1ebbe367faf/doc/conjure-client-clojure-nrepl.txt#L167-L197

oryband commented 1 year ago

I have babashka installed and available :!bb returns repl printout but it doesn't look like Conjure is running it - there is no .nrepl-port and the default port 8794 is unavailable (why is that btw?)

The issue surfaces even without babashka - When connecting to standard JVM Clojure repl. When quitting nvim it still hangs. In practice it means I can't quit when connecting to a REPL

oryband commented 1 year ago

The issue still persists with this configuration (client on load is enabled)

    { "Olical/conjure",
      ft = { "clojure" },
      version = "4.40.x",
      config = function()
        vim.api.nvim_set_var("conjure#client#clojure#nrepl#connection#auto_repl#enabled", false)
      end
    },
oryband commented 1 year ago

I've found out I had a hanging .nrepl-port file up my dir tree pointing to some random port 44479, i removed it and now auto-repl babashka is started and connected - but the problem persists. I don't think bb repl is related here since the issue also occurs if I connect to an existing JVM clojure repl.

Invertisment commented 1 year ago

I think that you should comment parts of your config until you find a problem.

oryband commented 1 year ago

I think that you should comment parts of your config until you find a problem.

I did - I'm just using default AstroNvim and the minimal configuration example I posted above

oryband commented 1 year ago

Notice the issue was introduced at 4.40.0 ; If I go back to 4.39.0 it doesn't reproduce and everything is fine

Invertisment commented 1 year ago

https://github.com/Olical/conjure/compare/v4.39.0...v4.40.0

oryband commented 1 year ago

Help?

Olical commented 1 year ago

I still can't reproduce your issue, have you tried it without the ft = { "clojure" }? The Clojure client's "on-load" function that you'd disabled to fix the issue only disables the initial connection to a .nrepl-port file. That's the only thing it removes, so it's somehow related to that.

Would you be able to set g:conjure#debug = v:true and capture the logs from startup? It'll have a few more details in there that might help.

oryband commented 1 year ago

@Olical Sure. Here's the output for v4.40.0 when opening a file called x.clj, inputting text defn and calling doc word on it. Notice the issue reproduces when I close nvim and I can't find documentation where I could read the debug log after closing nvim, so I'm not sure this would be helpful:

; Sponsored by @frenchy64 ❤
; --------------------------------------------------------------------------------
; No nREPL port file found
; Starting auto-repl: bb nrepl-server localhost:8794
; --------------------------------------------------------------------------------
; doc (word): defn
; --------------------------------------------------------------------------------
; localhost:8794 (connected): .nrepl-port
; debug: send
{:id "9b88028a-f0a5-424e-9b68-14c4d927da82" :op "describe"}
; debug: send
{:id "507e6d8b-5cce-43c9-9b6c-0564c9e67634" :op "ls-sessions"}
; debug: send
{:code "(ns conjure.internal  (:require [clojure.pprint :as pp]))(defn pprint [val w opts]  (apply pp/write val    (mapcat identity (assoc opts :stream w))))"
 :id "62778941-bfaf-4e54-949a-48e297588898"
 :op "eval"}
; debug: receive
{:id "9b88028a-f0a5-424e-9b68-14c4d927da82"
 :ops {:clone {}
       :close {}
       :complete {}
       :describe {}
       :eldoc {}
       :eval {}
       :info {}
       :load-file {}
       :lookup {}
       :ls-sessions {}}
 :session "none"
 :status ["done"]
 :versions {:babashka "1.3.176" :babashka.nrepl "0.0.6-SNAPSHOT"}}
; debug: receive
{:id "507e6d8b-5cce-43c9-9b6c-0564c9e67634"
 :session "none"
 :sessions {}
 :status ["done"]}
; debug: send
{:id "94c6b528-f532-4df1-8eb7-0c6c3e70c7e4" :op "clone"}
; debug: receive
{:id "62778941-bfaf-4e54-949a-48e297588898"
 :ns "conjure.internal"
 :session "none"
 :value "nil"}
; debug: receive
{:id "62778941-bfaf-4e54-949a-48e297588898"
 :ns "conjure.internal"
 :session "none"
 :value "#'conjure.internal/pprint"}
; debug: receive
{:id "62778941-bfaf-4e54-949a-48e297588898" :session "none" :status ["done"]}
; debug: send
{:code "(require 'clojure.repl)"
 :id "43a7fadb-5cb3-4603-a573-15d2eedc0437"
 :nrepl.middleware.print/options {:associative 1 :length 500 :level 50}
 :nrepl.middleware.print/print "conjure.internal/pprint"
 :op "eval"}
; debug: send
{:code "(clojure.repl/doc defn)"
 :column 1
 :file "/home/ory/Documents/x.clj"
 :id "be2db4a0-a233-40e7-8ebb-e58d76753211"
 :line 1
 :nrepl.middleware.print/options {:associative 1 :length 500 :level 50}
 :nrepl.middleware.print/print "conjure.internal/pprint"
 :op "eval"}
; debug: receive
{:id "94c6b528-f532-4df1-8eb7-0c6c3e70c7e4"
 :new-session "95c8418f-9102-4733-93f5-3260158b3093"
 :session "none"
 :status ["done"]}
; debug: send
{:code "#?(:clj 'clj :cljs 'cljs :cljr 'cljr :default 'unknown)"
 :id "c846f6b6-5bd3-4353-b2c1-1c9100299d77"
 :op "eval"
 :session "95c8418f-9102-4733-93f5-3260158b3093"}
; debug: receive
{:id "43a7fadb-5cb3-4603-a573-15d2eedc0437"
 :ns "conjure.internal"
 :session "none"
 :value "nil"}
; debug: receive
{:id "43a7fadb-5cb3-4603-a573-15d2eedc0437" :session "none" :status ["done"]}
; debug: receive
{:id "be2db4a0-a233-40e7-8ebb-e58d76753211"
 :out "-------------------------
"
 :session "none"}
; debug: receive
{:id "be2db4a0-a233-40e7-8ebb-e58d76753211"
 :out "clojure.core/defn
"
 :session "none"}
; debug: receive
{:id "be2db4a0-a233-40e7-8ebb-e58d76753211"
 :out "([name doc-string? attr-map? [params*] prepost-map? body] [name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?])
"
 :session "none"}
; debug: receive
{:id "be2db4a0-a233-40e7-8ebb-e58d76753211"
 :out "Macro
"
 :session "none"}
; debug: receive
{:id "be2db4a0-a233-40e7-8ebb-e58d76753211"
 :out "  Same as (def name (fn [params* ] exprs*)) or (def
    name (fn ([params* ] exprs*)+)) with any doc-string or attrs added
    to the var metadata. prepost-map defines a map with optional keys
    :pre and :post that contain collections of pre or post conditions.
"
 :session "none"}
; debug: receive
{:id "be2db4a0-a233-40e7-8ebb-e58d76753211"
 :ns "conjure.internal"
 :session "none"
 :value "nil"}
; debug: receive
{:id "be2db4a0-a233-40e7-8ebb-e58d76753211" :session "none" :status ["done"]}
; -------------------------
; clojure.core/defn
; ([name doc-string? attr-map? [params*] prepost-map? body] [name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?])
; Macro
;   Same as (def name (fn [params* ] exprs*)) or (def
;     name (fn ([params* ] exprs*)+)) with any doc-string or attrs added
;     to the var metadata. prepost-map defines a map with optional keys
;     :pre and :post that contain collections of pre or post conditions.
; debug: receive
{:id "c846f6b6-5bd3-4353-b2c1-1c9100299d77"
 :ns "conjure.internal"
 :session "95c8418f-9102-4733-93f5-3260158b3093"
 :value "clj"}
; debug: receive
{:id "c846f6b6-5bd3-4353-b2c1-1c9100299d77"
 :session "95c8418f-9102-4733-93f5-3260158b3093"
 :status ["done"]}
; --------------------------------------------------------------------------------
; Assumed session: Scottish Terrier (Clojure)
Olical commented 1 year ago

I've set up the same version of AstroNvim as you, installed Conjure, opened a Clojure file, evaluated a form and exited just fine 🤔 I'm currently on Neovim 0.9.0 since that's what Arch is providing me with. Your debug log looks fine, nothing out of the ordinary there... I'll try out the rest of your config if I can from your dotfiles.

Olical commented 1 year ago

Managed to run your AstroNvim user config, eval and close. On the version of Conjure you were using and the very latest one. I think something else is at play here but I'm not sure what.

I've done everything I can I think though, I've run your exact Neovim config (not sure what it tried to install but looked a little scary 😅 ) and it works absolutely fine for me. I'm not sure what else it could be unless it requires a specific CPU architecture or something.

Or is it to do with snap? I see you mentioned that in your initial details. I'm just installing Neovim from the Arch package manager.

Olical commented 1 year ago

Our only difference that I can see (other than machine and OS things) is Neovim version. I'm not sure why that'd make a difference though.

oryband commented 1 year ago

@Olical you've solved it for me! I just updated to Neovim 0.9.0 and it solved the issue. Thanks for following up. Now I can update to the most recent Conjure version, it's central to my job.

Olical commented 1 year ago

WEIRD! So sorry you ran into this issue, I'm very glad it's working now. I honestly don't know what could've caused this or why I couldn't reproduce it despite literally using your nvim config repo. Hopefully whatever weirdness caused that doesn't crop up again!

Invertisment commented 1 year ago

image

oryband commented 1 year ago

If interested you can downgrade to the Nvim version i used and maybe it'll reproduce there.

On Fri, May 12, 2023, 00:46 Martynas M @.***> wrote:

[image: image] https://user-images.githubusercontent.com/1641263/237820316-28f81409-052e-4613-a5e9-217d8f5eed81.png

— Reply to this email directly, view it on GitHub https://github.com/Olical/conjure/issues/481#issuecomment-1544724516, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA4FO7TCSYPUQZGF6T5OJTXFVM3XANCNFSM6AAAAAAXA4SQOY . You are receiving this because you modified the open/close state.Message ID: @.***>