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

REPL errors "randomly" after fake Pkg prompt PR #54754

Closed
KristofferC opened this issue Jun 10, 2024 · 7 comments · Fixed by #54760
Closed

REPL errors "randomly" after fake Pkg prompt PR #54754

KristofferC opened this issue Jun 10, 2024 · 7 comments · Fixed by #54760
Labels
REPL Julia's REPL (Read Eval Print Loop)
Milestone

Comments

@KristofferC
Copy link
Member

Just as an example:

image

(Base) julia> Base.explicit_loadUnhandled Task ERROR: TaskFailedException

    nested task error: ArgumentError: IOBuffer not marked
    Stacktrace:
     [1] reset
       @ ./io.jl:1429 [inlined]
     [2] reset
       @ ./stream.jl:1489 [inlined]
     [3] peek(s::TTY, ::Type{Char})
       @ Base ./stream.jl:1496
     [4] peek(t::REPL.Terminals.TTYTerminal, ::Type{Char})
       @ REPL.Terminals ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/Terminals.jl:161
     [5] (::REPL.LineEdit.var"#281#283"{REPL.Terminals.TTYTerminal})()
       @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/LineEdit.jl:2834
Stacktrace:
 [1] _wait_multiple(waiting_tasks::Tuple{Task, Task}, throwexc::Bool, all::Bool, failfast::Bool)
   @ Base ./task.jl:513
 [2] _wait_multiple
   @ ./task.jl:417 [inlined]
 [3] waitany
   @ ./task.jl:397 [inlined]
 [4] prompt!(term::REPL.Terminals.TextTerminal, prompt::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
   @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/LineEdit.jl:2833
 [5] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
   @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/LineEdit.jl:2743
 [6] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
   @ REPL ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:1504
 [7] (::REPL.var"#75#81"{REPL.LineEditREPL, REPL.REPLBackendRef})()
   @ REPL ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:496
ERROR: TaskFailedException
Stacktrace:
  [1] try_yieldto(undo::typeof(ensure_rescheduled))
    @ Base ./task.jl:1100
  [2] wait()
    @ Base ./task.jl:1164
  [3] wait(c::GenericCondition{ReentrantLock}; first::Bool)
    @ Base ./condition.jl:139
  [4] wait
    @ ./condition.jl:134 [inlined]
  [5] take_buffered(c::Channel{Any})
    @ Base ./channels.jl:493
  [6] take!
    @ ./channels.jl:487 [inlined]
  [7] repl_backend_loop(backend::REPL.REPLBackend, get_module::Function)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:353
  [8] start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:343
  [9] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_

Probably related to #54674 looking at the blame.

cc @IanButterworth

@KristofferC KristofferC added this to the 1.11 milestone Jun 10, 2024
@KristofferC KristofferC added the REPL Julia's REPL (Read Eval Print Loop) label Jun 10, 2024
@IanButterworth
Copy link
Member

Seems to be an issue with this line. Is there a more correct way to wait on input but not error on eof?

@async(eof(term) || peek(term, Char)),

@KristofferC KristofferC changed the title REPL errors "randomly" after fake Pkg prompt REPL errors "randomly" after fake Pkg prompt PR Jun 10, 2024
@vtjnash
Copy link
Member

vtjnash commented Jun 10, 2024

Normally, the way to do that is to have 2 separate tasks, each responsible for one event, instead of having 3 tasks, each responsible for a semi-arbitrary set of events

@IanButterworth
Copy link
Member

Sorry, I don't understand. Would you mind elaborating with code?

@vtjnash
Copy link
Member

vtjnash commented Jun 10, 2024

Split each thing you want to do into a separate task, and don't try to complicatedly intermix them by ever using waitany

@IanButterworth
Copy link
Member

I want to wait for the first of either

  • new input being available from stdin, but not consume it, because it's consumed inside match_input
  • a new function that needs executing from s.async_channel

The current design is the only way I know how to do that without blocking while waiting on stdin or throwing away new input on stdin

@vtjnash
Copy link
Member

vtjnash commented Jun 11, 2024

I think there are already a few other clients similar to that (e.g. see beep), though the current implementation of MVC does seem probably too tightly coupled between input and output to allow the clean injection of events that are not from the keymap

@vtjnash
Copy link
Member

vtjnash commented Jun 11, 2024

Reading from stdin without consuming the input introduces a data race into the design, which is probably why it crashes for some people periodically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants