Open rdeits opened 5 years ago
@hustf do you know how to gracefully handle this?
What I wonder is whether the app is GC'ed in spite of this error.
'End users' don't need even a one-liner I think.
WebSockets already hides the lowest level traces. The traces above are from Mux / WebIO. Since they are kind of intertwined, we'd need to revise both simultanously to use something like this approach:
import WebSockets.readguarded
while true
data, success = readguarded(sock)
!success && break
println(String(data))
end
I had some trouble developing master now. Instead, with Revise and a minimum change approach we can drop it all:
julia> using WebIO,Mux
import Mux.wcatch
wcatch(app, req) = app(req)
n = node(:div, "hello world")
webio_serve(page("/", req -> n), 8000)
@cstjean: I think it is. But to be sure, I like to break directly out of read /write loops without checking isopen or eof.
My tests with
finalizer(gui) do _
println("\n\n\n\n app was collected")
end
suggest that the app is never GC'ed :worried: . Refreshing the page over and over gradually increases memory usage without bounds, and calling GC.gc()
does not collect it.
app was collected
is printed many times when I close Julia, as the finalizers are run.
The bug
This was originally opened as https://github.com/rdeits/MeshCat.jl/issues/108 but I don't think there's anything I can do about it in MeshCat.jl directly. The problem is simply that rendering a WebIO scope in a browser window and then closing that window causes a long error stacktrace, even though the "error" is simply the normal closing of the websocket:
This does not actually break anything, but it makes using WebIO difficult, particularly when there are real errors mixed in with this noise. I've trained myself to ignore it, but it's hard to ask end-users to do the same.
Context
WebIO 0.8.11, Mux 0.7.0, HTTP 0.8.6, WebSockets 1.5.2.
MWE
open
localhost:8000
in your browser, then close the window and observe the backtrace output filling the Julia window.