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

Trying to narrow down the websockets issue #170

Closed
rdeits opened this issue Aug 11, 2018 · 0 comments
Closed

Trying to narrow down the websockets issue #170

rdeits opened this issue Aug 11, 2018 · 0 comments

Comments

@rdeits
Copy link
Collaborator

rdeits commented Aug 11, 2018

Using Mux.jl master, WebIO from #169 , HTTP.jl master, and WebSockets with JuliaWeb/WebSockets.jl#106 I think things are very close to working.

However, websocket connections from the browser still don't work. I think this is a minimal example that reproduces the error:

using WebIO
using JSON
using Sockets
using Mux

struct WebSockConnection <: WebIO.AbstractConnection
    sock
end

function Sockets.send(p::WebSockConnection, data)
    write(p.sock, sprint(io->JSON.print(io,data)))
end

Base.isopen(p::WebSockConnection) = isopen(p.sock)

function create_socket(req)
    @show req
    sock = req[:socket]
    conn = WebSockConnection(sock)

    t = @async while isopen(sock)
        data = read(sock)

        msg = JSON.parse(String(data))
        WebIO.dispatch(conn, msg)
    end

    wait(t)
end

websock = Mux.App(Mux.mux(
    Mux.wdefaults,
    Mux.route("/webio-socket", create_socket),
    Mux.wclose,
    Mux.notfound(),
))

port = 8005
Mux.serve(websock, port)

Just run the above lines, then, in a JS console, try to execute: ws = new WebSocket("ws://localhost:8005/webio-socket")

I see the following error message (in Julia) when I do that:

Error handling websocket connection:
KeyError: key :socket not found
Stacktrace:
 [1] getindex at ./dict.jl:478 [inlined]
 [2] macro expansion at ./show.jl:556 [inlined]
 [3] create_socket(::Dict{Any,Any}) at /home/rdeits/.julia/dev/WebIO/mux-ws-test.jl:17
 [4] (::getfield(Mux, Symbol("##5#6")){getfield(Mux, Symbol("##27#28")){Array{SubString{String},1}},typeof(create_socket)})(::Function, ::Dict{Any,Any}) at /home/rdeits/.julia/dev/Mux/src/Mux.jl:18
 [5] #1 at /home/rdeits/.julia/dev/Mux/src/Mux.jl:11 [inlined]
 [6] splitquery(::getfield(Mux, Symbol("##1#2")){getfield(Mux, Symbol("##5#6")){getfield(Mux, Symbol("##27#28")){Array{SubString{String},1}},typeof(create_socket)},getfield(Mux, Symbol("##1#2")){typeof(Mux.wclose),getfield(Mux, Symbol("##1#2")){getfield(Mux, Symbol("##17#18")){getfield(Mux, Symbol("##21#22")){Symbol,Int64}},getfield(Mux, Symbol("##19#20")){String}}}}, ::Dict{Any,Any}) at /home/rdeits/.julia/dev/Mux/src/basics.jl:32
 [7] #1 at /home/rdeits/.julia/dev/Mux/src/Mux.jl:11 [inlined]
 [8] wcatch(::getfield(Mux, Symbol("##1#2")){typeof(Mux.splitquery),getfield(Mux, Symbol("##1#2")){getfield(Mux, Symbol("##5#6")){getfield(Mux, Symbol("##27#28")){Array{SubString{String},1}},typeof(create_socket)},getfield(Mux, Symbol("##1#2")){typeof(Mux.wclose),getfield(Mux, Symbol("##1#2")){getfield(Mux, Symbol("##17#18")){getfield(Mux, Symbol("##21#22")){Symbol,Int64}},getfield(Mux, Symbol("##19#20")){String}}}}}, ::Dict{Any,Any}) at /home/rdeits/.julia/dev/Mux/src/websockets_integration.jl:12
 [9] #1 at /home/rdeits/.julia/dev/Mux/src/Mux.jl:11 [inlined]
 [10] todict(::getfield(Mux, Symbol("##1#2")){typeof(Mux.wcatch),getfield(Mux, Symbol("##1#2")){typeof(Mux.splitquery),getfield(Mux, Symbol("##1#2")){getfield(Mux, Symbol("##5#6")){getfield(Mux, Symbol("##27#28")){Array{SubString{String},1}},typeof(create_socket)},getfield(Mux, Symbol("##1#2")){typeof(Mux.wclose),getfield(Mux, Symbol("##1#2")){getfield(Mux, Symbol("##17#18")){getfield(Mux, Symbol("##21#22")){Symbol,Int64}},getfield(Mux, Symbol("##19#20")){String}}}}}}, ::HTTP.Messages.Request) at /home/rdeits/.julia/dev/Mux/src/basics.jl:23
 [11] #3 at /home/rdeits/.julia/dev/Mux/src/Mux.jl:15 [inlined] (repeats 2 times)
 [12] (::getfield(Mux, Symbol("##1#2")){getfield(Mux, Symbol("##3#4")){getfield(Mux, Symbol("##3#4")){typeof(Mux.todict),typeof(Mux.wcatch)},typeof(Mux.splitquery)},getfield(Mux, Symbol("##1#2")){getfield(Mux, Symbol("##5#6")){getfield(Mux, Symbol("##27#28")){Array{SubString{String},1}},typeof(create_socket)},getfield(Mux, Symbol("##1#2")){typeof(Mux.wclose),getfield(Mux, Symbol("##1#2")){getfield(Mux, Symbol("##17#18")){getfield(Mux, Symbol("##21#22")){Symbol,Int64}},getfield(Mux, Symbol("##19#20")){String}}}}})(::HTTP.Messages.Request) at /home/rdeits/.julia/dev/Mux/src/Mux.jl:11
 [13] (::getfield(Mux, Symbol("##7#8")){Mux.App})(::HTTP.Messages.Request) at /home/rdeits/.julia/dev/Mux/src/server.jl:42
 [14] handle at /home/rdeits/.julia/dev/HTTP/src/Handlers.jl:35 [inlined]
 [15] #7 at /home/rdeits/.julia/dev/HTTP/src/Servers.jl:170 [inlined]
 [16] handle_request(::getfield(HTTP.Servers, Symbol("##7#11")){HTTP.Servers.Server{HTTP.Servers.http,HTTP.Handlers.HandlerFunction{getfield(Mux, Symbol("##7#8")){Mux.App}}}}, ::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{TCPSocket}}) at /home/rdeits/.julia/dev/HTTP/src/Servers.jl:525
 [17] handle_stream(::getfield(HTTP.Servers, Symbol("##7#11")){HTTP.Servers.Server{HTTP.Servers.http,HTTP.Handlers.HandlerFunction{getfield(Mux, Symbol("##7#8")){Mux.App}}}}, ::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{TCPSocket}}) at /home/rdeits/.julia/dev/HTTP/src/Servers.jl:501
 [18] (::getfield(HTTP.Servers, Symbol("##54#55")){getfield(HTTP.Servers, Symbol("##7#11")){HTTP.Servers.Server{HTTP.Servers.http,HTTP.Handlers.HandlerFunction{getfield(Mux, Symbol("##7#8")){Mux.App}}}},HTTP.ConnectionPool.Transaction{TCPSocket},HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{TCPSocket}}})() at ./task.jl:262┌ Error: (MethodError(convert, (HTTP.Messages.Response, nothing), 0x0000000000006c70), Base.StackTraces.StackFrame[setproperty!(::Request, ::Symbol, ::Nothing) at sysimg.jl:19, handle_request(::##7#11{Server{http,HandlerFunction{##7#8{App}}}}, ::Stream{Request,Transaction{TCPSocket}}) at Servers.jl:525, handle_stream(::##7#11{Server{http,HandlerFunction{##7#8{App}}}}, ::Stream{Request,Transaction{TCPSocket}}) at Servers.jl:501, (::##54#55{##7#11{Server{http,HandlerFunction{##7#8{App}}}},Transaction{TCPSocket},Stream{Request,Transaction{TCPSocket}}})() at task.jl:262])

We're expecting the req to contain a socket entry, but it doesn't (it's only keys are: Any[:query, :method, :params, :path, :data, :headers]). Maybe this is something that changed in the new HTTP.jl upgrade?

@rdeits rdeits closed this as completed Aug 13, 2018
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