JuliaGizmos / Interact.jl

Interactive widgets to play with your Julia code
Other
522 stars 77 forks source link

mux minimal slider examples doesn't work #419

Open freemin7 opened 7 months ago

freemin7 commented 7 months ago
(MuxInteract) pkg> st
Status `~/MuxInteract/Project.toml`
  [5ae59095] Colors v0.12.10
  [c601a237] Interact v0.10.5
  [a975b10e] Mux v1.0.1
  [0f1e0344] WebIO v0.8.21
 using Interact, Mux, WebIO

 s = slider(1:100);

function app(req) # req is a Mux request dictionary
  println(req); return s
end

webio_serve(page("/", app), 8000)

Upon loading the website i get this in the REPL:

Dict{Any, Any}(:query => "", :method => "GET", :params => Dict{Any, Any}(), :path => SubString{String}[], :cookies => HTTP.Cookies.Cookie[HTTP.Cookies.Cookie("secret", "QeJ7ec6w", "", "", Dates.DateTime("0001-01-01T00:00:00"), "", Dates.DateTime("0001-01-01T00:00:00"), Dates.DateTime("0001-01-01T00:00:00"), 0, false, false, false, false, HTTP.Cookies.SameSiteDefaultMode, "secret=QeJ7ec6w", String[])], :uri => URI("/"), :data => UInt8[], :headers => Pair{SubString{String}, SubString{String}}["Host" => "localhost:8000", "User-Agent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0", "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", "Accept-Language" => "en-US,en;q=0.5", "Accept-Encoding" => "gzip, deflate, br", "Connection" => "keep-alive", "Cookie" => "secret=QeJ7ec6w", "Upgrade-Insecure-Requests" => "1", "Sec-Fetch-Dest" => "document", "Sec-Fetch-Mode" => "navigate", "Sec-Fetch-Site" => "none", "Sec-Fetch-User" => "?1"])
Error handling websocket connection:
TaskFailedException
Stacktrace:
  [1] wait
    @ ./task.jl:349 [inlined]
  [2] create_socket(req::Dict{Any, Any})
    @ WebIO ~/.julia/packages/WebIO/8Xm9p/src/providers/mux.jl:47
  [3] (::Mux.var"#5#6"{Mux.var"#29#30"{Vector{SubString{String}}}, typeof(WebIO.create_socket)})(f::Function, x::Dict{Any, Any})
    @ Mux ~/.julia/packages/Mux/PipQ9/src/Mux.jl:17
  [4] (::Mux.var"#1#2"{Mux.var"#5#6"{Mux.var"#29#30"{Vector{SubString{String}}}, typeof(WebIO.create_socket)}, Mux.var"#1#2"{typeof(Mux.wclose), Mux.var"#1#2"{Mux.var"#19#20"{Mux.var"#23#24"{Symbol, Int64}}, Mux.var"#21#22"{String}}}})(x::Dict{Any, Any})
    @ Mux ~/.julia/packages/Mux/PipQ9/src/Mux.jl:10
  [5] splitquery(app::Mux.var"#1#2"{Mux.var"#5#6"{Mux.var"#29#30"{Vector{SubString{String}}}, typeof(WebIO.create_socket)}, Mux.var"#1#2"{typeof(Mux.wclose), Mux.var"#1#2"{Mux.var"#19#20"{Mux.var"#23#24"{Symbol, Int64}}, Mux.var"#21#22"{String}}}}, req::Dict{Any, Any})
    @ Mux ~/.julia/packages/Mux/PipQ9/src/basics.jl:31
  [6] #1
    @ ~/.julia/packages/Mux/PipQ9/src/Mux.jl:10 [inlined]
  [7] wcatch(app::Mux.var"#1#2"{typeof(Mux.splitquery), Mux.var"#1#2"{Mux.var"#5#6"{Mux.var"#29#30"{Vector{SubString{String}}}, typeof(WebIO.create_socket)}, Mux.var"#1#2"{typeof(Mux.wclose), Mux.var"#1#2"{Mux.var"#19#20"{Mux.var"#23#24"{Symbol, Int64}}, Mux.var"#21#22"{String}}}}}, req::Dict{Any, Any})
    @ Mux ~/.julia/packages/Mux/PipQ9/src/websockets_integration.jl:11
  [8] #1
    @ ~/.julia/packages/Mux/PipQ9/src/Mux.jl:10 [inlined]
  [9] todict
    @ ~/.julia/packages/Mux/PipQ9/src/basics.jl:25 [inlined]
 [10] #3 (repeats 2 times)
    @ ~/.julia/packages/Mux/PipQ9/src/Mux.jl:14 [inlined]
 [11] (::Mux.var"#1#2"{Mux.var"#3#4"{Mux.var"#3#4"{typeof(Mux.todict), typeof(Mux.wcatch)}, typeof(Mux.splitquery)}, Mux.var"#1#2"{Mux.var"#5#6"{Mux.var"#29#30"{Vector{SubString{String}}}, typeof(WebIO.create_socket)}, Mux.var"#1#2"{typeof(Mux.wclose), Mux.var"#1#2"{Mux.var"#19#20"{Mux.var"#23#24"{Symbol, Int64}}, Mux.var"#21#22"{String}}}}})(x::HTTP.WebSockets.WebSocket)
    @ Mux ~/.julia/packages/Mux/PipQ9/src/Mux.jl:10
 [12] (::Mux.var"#9#10"{Mux.App})(sock::HTTP.WebSockets.WebSocket)
    @ Mux ~/.julia/packages/Mux/PipQ9/src/server.jl:48
 [13] upgrade(f::Mux.var"#9#10"{Mux.App}, http::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}; suppress_close_error::Bool, maxframesize::Int64, maxfragmentation::Int64, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ HTTP.WebSockets ~/.julia/packages/HTTP/bDoga/src/WebSockets.jl:440
 [14] upgrade
    @ ~/.julia/packages/HTTP/bDoga/src/WebSockets.jl:420 [inlined]
 [15] (::Mux.var"#14#15"{Mux.App, Mux.App})(http::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}})
    @ Mux ~/.julia/packages/Mux/PipQ9/src/server.jl:81
 [16] #invokelatest#2
    @ ./essentials.jl:819 [inlined]
 [17] invokelatest
    @ ./essentials.jl:816 [inlined]
 [18] handle_connection(f::Function, c::HTTP.Connections.Connection{Sockets.TCPSocket}, listener::HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, readtimeout::Int64, access_log::Nothing)
    @ HTTP.Servers ~/.julia/packages/HTTP/bDoga/src/Servers.jl:450
 [19] macro expansion
    @ ~/.julia/packages/HTTP/bDoga/src/Servers.jl:386 [inlined]
 [20] (::HTTP.Servers.var"#16#17"{Mux.var"#14#15"{Mux.App, Mux.App}, HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, Set{HTTP.Connections.Connection}, Int64, Nothing, Base.Semaphore, HTTP.Connections.Connection{Sockets.TCPSocket}})()
    @ HTTP.Servers ./task.jl:514

    nested task error: MethodError: no method matching isopen(::HTTP.WebSockets.WebSocket)

    Closest candidates are:
      isopen(::Union{Base.DevNull, Core.CoreSTDERR, Core.CoreSTDOUT})
       @ Base coreio.jl:24
      isopen(::Union{Base.AsyncCondition, Timer})
       @ Base asyncevent.jl:160
      isopen(::Channel)
       @ Base channels.jl:214
      ...

    Stacktrace:
     [1] (::WebIO.var"#98#99"{WebIO.WebSockConnection, HTTP.WebSockets.WebSocket})()
       @ WebIO ./task.jl:514

and s[] isn't updated.

Benoit9 commented 6 months ago

I have the same issue, and I believe it is also documented in the WebIO project:

https://github.com/JuliaGizmos/WebIO.jl/issues/513

The "fix" is to downgrade WebSockets to version 1.5.9, which in turn downgrades Mux, HTTP, etc., so not a great solution.