JuliaGizmos / WebIO.jl

A bridge between Julia and the Web.
https://juliagizmos.github.io/WebIO.jl/latest/
Other
228 stars 64 forks source link

Compatibility issues with WebIO 0.4.1 #219

Closed rdeits closed 5 years ago

rdeits commented 5 years ago

Hey all, I'm sorry I don't have time to dig into what exactly is going on, but I've noticed that MeshCat is totally broken on WebIO 0.4.1, while it works fine with 0.4.0. It's easy to test by just installing MeshCat and running:

julia> using MeshCat

julia> open(Visualizer())

With WebIO v0.4.0, this will open a new browser tab with an empty 3D world (after a couple seconds). But with WebIO v0.4.1, the tab is just blank forever. It looks like the Julia server is probably never responding to the browser's request for the page content.

Anyway, I'll try to debug this more if I have time, but I wanted to let you all know right away.

shashi commented 5 years ago

I can reproduce this, but still looking for clues to see what's going on.

shashi commented 5 years ago
$ telnet 127.0.0.1 8700
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
GET / HTTP/1.1
Host: 127.0.0.1

Well the server doesn't respond to the first request itself.

shashi commented 5 years ago

On the other hand on v0.4.0:

GET / HTTP/1.1
Host: 127.0.0.1

HTTP/1.1 200 OK
Transfer-Encoding: chunked

920
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <script src="/assetserver/e8f953a4abf5e4095b83e225fc5e11254819fa44-assets/webio/dist/bundle.js"></script>
    <script src="/assetserver/e8f953a4abf5e4095b83e225fc5e11254819fa44-assets/providers/mux_setup.js"></script>
  </head>
...
shashi commented 5 years ago

reverting https://github.com/JuliaGizmos/WebIO.jl/pull/206 makes the problem go away cc @SimonDanisch

Note that the silence may have something to do with the fact that tasks that are not waited on no more print an error and fail silently.

shashi commented 5 years ago

I tried with this patch but nothing gets printed:

diff --git a/src/servers.jl b/src/servers.jl
index a36c0d3..04f8753 100644
--- a/src/servers.jl
+++ b/src/servers.jl
@@ -7,7 +7,16 @@ end
 Base.open(vis::Visualizer, args...; kw...) = open(vis.core, args...; kw...)

 function Base.open(core::CoreVisualizer, port::Integer)
-    @async WebIO.webio_serve(Mux.page("/", req -> core.scope), port)
+    @async begin
+        try
+            WebIO.webio_serve(Mux.page("/", req -> core.scope), port)
+        catch err
+            bt = catch_backtrace()
+            Base.showerror(stderr, err)
+            Base.show_backtrace(stderr, bt)
+            rethrow(err)
+        end
+    end
     url = "http://127.0.0.1:$port"
     Compat.@info("Serving MeshCat visualizer at $url")
     open_url(url)
@@ -20,7 +29,7 @@ function open_url(url)
         elseif Compat.Sys.isapple()
             run(`open $url`)
         elseif Compat.Sys.islinux()
-            run(`xdg-open $url`)
+            #run(`xdg-open $url`)
         end
     catch e
         println("Could not open browser automatically: $e")

A good thing to check would be to load the viz code in a notebook and see if it throws (that should invoke the suspect import.jl code paths). Or else the last resort is to stare at Simon's patch and/or write tests for it.

SimonDanisch commented 5 years ago

weird, no code path that I touched in #206 seems to get hit, as far as I can tell....

SimonDanisch commented 5 years ago

But I can verify, that checking out exactly one commit before https://github.com/JuliaGizmos/WebIO.jl/commit/fef1012b429a501649dbff27d5515de6f62a9c83 works, while https://github.com/JuliaGizmos/WebIO.jl/commit/fef1012b429a501649dbff27d5515de6f62a9c83 doesn't work....

SimonDanisch commented 5 years ago

Maaaaan, can we at some point really make sure that HTTP + Mux etc don't just sent all errors to nirvanna?! The time I've spent debugging issues like this, untill it boils down to a super simple error is ridicilulous. It did actually hit my code path, but since I was doing print(name) and name == nothing it silently errored in the first instance -.-

show(stdout, MIME"text/html"(), vis.core.scope)

yields:

File /assetserver/1fb2bc85afe4f8311cf4faa558294a078ce840e8-main.min.js not found
error(::String) at error.jl:33
path2url(::SubString{String}) at imports.jl:38
dep2url(::String) at imports.jl:48
lowerdeps(::Nothing, ::String) at imports.jl:58
lowerdeps at imports.jl:72 [inlined]
iterate at generator.jl:47 [inlined]
_collect(::Array{String,1}, ::Base.Generator{Array{String,1},typeof(WebIO.lowerdeps)}, ::Base.EltypeUnknown, ::Base.HasShape{1}) at array.jl:632
map at array.jl:561 [inlined]
lowerdeps(::Array{String,1}) at imports.jl:90
lower(::Scope) at scope.jl:231
lower(::Node{Scope}) at node.jl:84
#show_json#3 at Writer.jl:313 [inlined]
show_json at Writer.jl:323 [inlined]
jsexpr at syntax.jl:114 [inlined]
(::getfield(WebIO, Symbol("##4#5")){Node{Scope}})(::Base.GenericIOBuffer{Array{UInt8,1}}) at node.jl:111
#sprint#325(::Nothing, ::Int64, ::Function, ::Function) at io.jl:101
sprint at io.jl:97 [inlined]
show(::Base.TTY, ::MIME{Symbol("text/html")}, ::Node{Scope}) at node.jl:111
show(::Base.TTY, ::MIME{Symbol("text/html")}, ::Scope) at scope.jl:357
top-level scope at none:0
include_string(::Module, ::String, ::String) at loading.jl:1002
include_string(::Module, ::String, ::String, ::Int64) at eval.jl:30
(::getfield(Atom, Symbol("##114#119")){String,Int64,String})() at eval.jl:94
withpath(::getfield(Atom, Symbol("##114#119")){String,Int64,String}, ::Nothing) at utils.jl:30
withpath at eval.jl:46 [inlined]
#113 at eval.jl:93 [inlined]
with_logstate(::getfield(Atom, Symbol("##113#118")){String,Int64,String}, ::Base.CoreLogging.LogState) at logging.jl:397
with_logger at logging.jl:493 [inlined]
#112 at eval.jl:92 [inlined]
hideprompt(::getfield(Atom, Symbol("##112#117")){String,Int64,String}) at repl.jl:85
macro expansion at eval.jl:91 [inlined]
(::getfield(Atom, Symbol("##111#116")))(::Dict{String,Any}) at eval.jl:86
handlemsg(::Dict{String,Any}, ::Dict{String,Any}) at comm.jl:164
(::getfield(Atom, Symbol("##19#21")){Array{Any,1}})() at task.jl:259

So the problem seems, that imp = "/assetserver/1fb2bc85afe4f8311cf4faa558294a078ce840e8-main.min.js"... Should we allow this? I expected that function to be either a file or an URL - but this is a relative url, so it neither matches the url format nor is it a local file... Should we disallow this to better check for missing files and actually fix this in meshcat? In any case, I pushed a fix to https://github.com/JuliaGizmos/WebIO.jl/pull/223

pfitzseb commented 5 years ago

I think I actually ran into this yesterday as well -- I was trying to use AssetRegistry to register a local file and then thought it would be a good idea to use the key returned by AssetRegistry.register instead of the file path. Imho that's a valid thing to do.

SimonDanisch commented 5 years ago

Yeah, but then we should specifically check with assetregistry, so that we're still able to throw (a surpressed :P) error when a file isn't found ;)

pfitzseb commented 5 years ago

Right, so just add a

elseif path in keys(AssetRegsitry.registry)
  return path

?

SimonDanisch commented 5 years ago

yeah why not... could add a startswith("/assetpath/", ...) to also allow the relative url part

shashi commented 5 years ago

Well it seems like disallowing automatic register may be saner at this point then? We can do that.

shashi commented 5 years ago

Maaaaan, can we at some point really make sure that HTTP + Mux etc don't just sent all errors to nirvanna?!

That diff was our best hope...

SimonDanisch commented 5 years ago

we could do a bit better with the generic_http provider I think... Maybe I should add a serve function to it, and add the right try catches^^

pfitzseb commented 5 years ago

Things should also get better after we update to the new HTTP.jl, right?

SimonDanisch commented 5 years ago

yeah, at least we won't need to wrap it into a null logger anymore :D But that's a different issue - Mux doesn't do that, but I think it does catch the errors? Not sure, there are multiple locations where things go awry^^