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

Add WebSocketHandler helper for websocket-based FrontendConnection extensions #247

Merged
merged 8 commits into from
Sep 3, 2024

Conversation

frankier
Copy link
Contributor

Previously outlined here: #244

@frankier
Copy link
Contributor Author

@SimonDanisch Could you please approve my workflows? :o)

@frankier
Copy link
Contributor Author

I think the CI is timing out, but it does not appear to obviously be related to the content of the PR.

Looks like the documentation preview wasn't built because the PR is from a fork.

@SimonDanisch
Copy link
Owner

It does seem to be related?

Warning: error while cleaning up server
│   exception =
│    MethodError: no method matching isopen(::Nothing)
│    Closest candidates are:
│      isopen(!Matched::Union{Base.AsyncCondition, Timer}) at asyncevent.jl:138
│      isopen(!Matched::Base.AbstractPipe) at io.jl:385
│      isopen(!Matched::HTTP.Servers.Server) at /home/runner/.julia/packages/HTTP/sJD5V/src/Servers.jl:127
│      ...
│    Stacktrace:
│     [1] isopen(ws::WebSocketConnection)
│       @ Bonito ~/work/Bonito.jl/Bonito.jl/src/connection/websocket.jl:14
│     [2] isopen(session::Session{WebSocketConnection})
│       @ Bonito ~/work/Bonito.jl/Bonito.jl/src/session.jl:162
│     [3] (::Bonito.var"#100#101"{Server, Set{WebSocketConnection}})()
│       @ Bonito ~/work/Bonito.jl/Bonito.jl/src/connection/websocket.jl:87
│     [4] lock(f::Bonito.var"#100#101"{Server, Set{WebSocketConnection}}, l::ReentrantLock)
│       @ Base ./lock.jl:187
│     [5] cleanup_server
│       @ ~/work/Bonito.jl/Bonito.jl/src/connection/websocket.jl:75 [inlined]
│     [6] macro expansion
│       @ ~/work/Bonito.jl/Bonito.jl/src/connection/websocket.jl:112 [inlined]
│     [7] (::Bonito.var"#103#105"{Server})()
│       @ Bonito ./task.jl:417
└ @ Bonito ~/work/Bonito.jl/Bonito.jl/src/connection/websocket.jl:115

@frankier
Copy link
Contributor Author

Ah. Looks like I pushed a slightly different version from the one I had manually tested. For some reason. I have trouble running the tests locally (they seem to pop up a few windows and then freeze indefinitely).

As for the CI, when I inspect the output it looks like it's timed out after 6 hours and all of the output after the first 50 lines (featuring package installs) is blank so I don't see the error you pasted.

@frankier
Copy link
Contributor Author

I'll wait to see how #248 gets fixed and then rebase + try to fix this.

@frankier
Copy link
Contributor Author

frankier commented Sep 3, 2024

Figured out the problem -- it was rather simple and but not fully obvious due to exceptions not printing in sub threads -- it should work now. I was able to run the tests locally using xvfb-run.

Can still hold off until #251 if you like

@SimonDanisch
Copy link
Owner

it was rather simple and but not fully obvious due to exceptions not printing in sub threads

I did run into this as well... Not really clear why though -.- I suspect apply_handler to suck up exceptions in HTTP.jl, so maybe we need a try catch there to show them ourselves.

function run_connection_loop(session::Session, handler::WebSocketHandler, websocket::WebSocket)
@debug("opening ws connection for session: $(session.id)")
handler.socket = websocket
while !isclosed(websocket)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be isopen(handler) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is copied from

while !isclosed(websocket)

The reference for the method is here https://juliaweb.github.io/HTTP.jl/stable/reference/#HTTP.WebSockets.isclosed

Do you mean Base.isopen? Is it the opposite?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just realized I have these comments in our isopen implementation:

function Base.isopen(ws::WebSocketHandler)
isnothing(ws.socket) && return false
# isclosed(ws.socket) returns readclosed && writeclosed
# but we consider it closed if either is closed?
if ws.socket.readclosed || ws.socket.writeclosed
return false
end
# So, it turns out, ws connection where the tab gets closed
# stay open indefinitely, but aren't writable anymore
# TODO, figure out how to check for that
return true
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay done since it seems fine to change then. It should just mean we get rid of half-closed sockets quicker I suppose.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what I hope :) Although, the web does keep surprising me!

@SimonDanisch SimonDanisch merged commit 032c46b into SimonDanisch:master Sep 3, 2024
3 checks passed
@SimonDanisch
Copy link
Owner

Thank you :)

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

Successfully merging this pull request may close these issues.

2 participants