JuliaWeb / WebSockets.jl

A WebSockets library for Julia
MIT License
157 stars 58 forks source link

Multiple ServerWS currently shares channels. #148

Closed hustf closed 5 years ago

hustf commented 5 years ago
const DEFAULTOPTIONS = (in = Channel(1),
                    out = Channel(2),

creates instances of channels. These are passed by reference to every new instances of ServerWS.

Consequences of .in and .out being shared between instances: All ServerWS instances would be closed when closing one of them. Error messages would seem to originate from another ServerWS.

This returning true indicates that the bug isn't fixed:

           h(r) = WebSockets.Response(200)
           w(s) = nothing
           sws1 = WebSockets.ServerWS(h, w)
           sws2 = WebSockets.ServerWS(h, w)
           put!(sws1.in, "Close")
           isready(sws2.in)  -> true

This workaround currently returns false and shows how to generate new channels every time:

           h(r) = WebSockets.Response(200)
           w(s) = nothing
           sws1 = WebSockets.ServerWS(h, w)
           sws2 = WebSockets.ServerWS(h, w, in = Channel(1), out = Channel(2))
           put!(sws1.in, "Close")
           isready(sws2.in)  -> false
EricForgy commented 5 years ago

😅

hustf commented 5 years ago

I'm thinking replacing const DEFAULTOPTIONS with defaultoptions()

would solve this.