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

OhMyRepl crashes julia-snail #173

Open
Paul-Roux-Phys opened this issue Jan 23, 2025 · 5 comments
Open

OhMyRepl crashes julia-snail #173

Paul-Roux-Phys opened this issue Jan 23, 2025 · 5 comments

Comments

@Paul-Roux-Phys
Copy link

Paul-Roux-Phys commented Jan 23, 2025

I recently installed julia-snail.

I experienced a bug when trying to launch julia-snail with C-c C-z, and got

Starting Julia process and loading Snail...
Snail connecting to Julia process, attempt 1/15...
Snail connecting to Julia process, attempt 2/15...
Snail connecting to Julia process, attempt 3/15...
Snail connecting to Julia process, attempt 4/15...
Snail connecting to Julia process, attempt 5/15...
Snail connecting to Julia process, attempt 6/15...
Snail connecting to Julia process, attempt 7/15...
Snail connecting to Julia process, attempt 8/15...
Snail connecting to Julia process, attempt 9/15...
Snail connecting to Julia process, attempt 10/15...
Snail connecting to Julia process, attempt 11/15...
Snail connecting to Julia process, attempt 12/15...
Snail connecting to Julia process, attempt 13/15...
Snail connecting to Julia process, attempt 14/15...
Snail connecting to Julia process, attempt 15/15...
julia-snail--repl-enable: Failed to connect to Snail server
julia-snail--send-to-server: Buffer *julia* process has no process

In the REPL buffer I would see

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.2 (2024-12-01)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

and then only once the last attempt to make a connection was finished, I got the line

julia> JuliaSnail.start(10011) ; # please wait, time-to-first-plot...

Then I didn't find a way to make a connection again.

The problem disappeared when I removed the lines

atreplinit() do repl
    try
        @eval using OhMyREPL
    catch e
        @warn "Error initializing OhMyRepl" exception = (e, catch_backtrace())
    end
end

from my startup.jl file, hence there seems to be an incompatibility between the OhMyREPL initialization and the julia-snail initialization.

Apologies if the issue is poorly written, I have little experience doing this.

@gcv
Copy link
Owner

gcv commented Jan 23, 2025

Strange. I cannot reproduce the problem. Using Julia 1.11.3 to test. I did have to use this workaround to get OhMyREPL to load from the startup file.

I can think of two possibilities. One, maybe OhMyREPL initialization and precompilation do something unexpected. Does it fully work for you from a non-Snail REPL instance? Two, maybe your OhMyREPL setup confuses the Snail prompt detector. Do you customize your Julia prompt in some unusual way? Extra colors, extra text?

@Paul-Roux-Phys
Copy link
Author

I'm on Julia 1.11.2.
I tried with the same code as you linked to for loading OhMyREPL but it did not change anything. My REPL launches fine outside of Snail. I don't have any setup at all for OhMyREPL or my Julia prompt. The only thing I do have is a custom zsh prompt (oh-my-posh), but I don't think that should interfere?

@gcv
Copy link
Owner

gcv commented Jan 24, 2025

Do you use vterm or eat for the Snail REPL? If it’s vterm, could you try eat?

@Paul-Roux-Phys
Copy link
Author

I use vterm. I tried with eat, got the exact same behaviour (except for some reason I don't have any colors in my eat buffer, didn't check if this has anything to do with Julia).

I figured if I call (julia-snail--repl-enable) from inside the vterm buffer then snail retries to start the server from the repl, which gives an error since it's already running:

julia> JuliaSnail.start(10011) ; # please wait, time-to-first-plot...
ERROR: IOError: listen: address already in use (EADDRINUSE)
Stacktrace:
 [1] uv_error
   @ ./libuv.jl:106 [inlined]
 [2] #listen#13
   @ /nix/store/wc3b5zkh1ffzl5qi26wy964b27dn6f8h-julia-bin-1.11.2/share/julia/stdlib/v1.11/Sockets/src/Sockets.jl:632 [inlined]
 [3] listen

But then Snail still manages to connect to the REPL session, I get the message

"Snail initialization complete. Happy hacking!"

and I can go on with the session.

I believe the problem comes from how snail detects the Julia initialization: I get

JuliaSnail.start(10011) ; # please wait, time-to-first-plot...
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.2 (2024-12-01)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

and then once the 15 failed attempts finish, the server gets initialised:

julia> JuliaSnail.start(10011) ; # please wait, time-to-first-plot...

Could it be my zsh prompt (zsh is my default shell which gets initialised with any vterm buffer) interfering?

@gcv
Copy link
Owner

gcv commented Jan 24, 2025

I don't think zsh has anything to do with it. This looks like the unfortunately synchronous dance between getting Julia to start a Snail server and for Emacs to try connecting to it has some missteps. The idea is this:

  1. Wait for a basic Julia REPL to start. This is marked by the string "julia>" appearing in the REPL buffer. This waits for 3 seconds (3000 ms), polling the buffer every 100 ms (julia-snail--wait-while). This was necessary due to some limitations in Julia 1.0 six years ago, but maybe it's time to revisit them — there might be a better way to bootstrap a Snail server now.
  2. Then the Snail server starts. Because of installing dependencies and TTFP, this can take a while. This will improve once I eliminate all external dependencies (which really just means CSTParser). That also waits for "julia>" to reappear.
  3. Finally, Emacs tries to connect. This is where you see 15 attempts. That you're seeing these 15 attempts at all is suspicious. Because of the delay in step 2, it should succeed on the first attempt. Maybe the 2nd if the networking stack is acting up.

Maybe OhMyREPL initialization takes such a long time that it hits the delay timeouts. What if you change the original REPL wait delay from 3000 ms to 5000 ms (or even 30000 ms)? The delay is relatively short because there is no good code in there (at least right now) to detect a Julia crash on startup, and it's weird if it doesn't fail quickly.

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

2 participants