-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Broken pipe on WebSocketHandler #9135
Comments
same problem with 0.33? |
@rdp @jhass I have created a repo to easily replicate this issue https://github.com/sardaukar/websocket_issue let me know if you see it too |
@rdp and yes, same problem in 0.33 and 0.34 for me |
FWIW I think it's expected (browser cuts the connection) ... though to be
honest...it might be nice to have cleaned output if a client breaks a
connection "gracefully between requests" (for http or https or websocket)
instead of a very large, full backtrace...hmm...
…On Tue, Apr 21, 2020 at 1:36 AM Bruno Antunes ***@***.***> wrote:
@rdp <https://github.com/rdp> and yes, same problem in 0.33 and 0.34 for
me
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9135 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAADBUBKW5DDTYQA2SKHXILRNVEHZANCNFSM4ML7GOUQ>
.
|
Not sure why there are disconnects so often if it's localhost, though... And also, why can't this be |
It cannot be rescued because it simply doesn't touch your code. It runs in a fiber and is triggered in standard library code there after all your callbacks already returned. Edit: sorry for the duplicates, github's downtime caused these :/ |
This comment has been minimized.
This comment has been minimized.
This is being improved by #9115 by not logging as errors the client disconnections |
Yeah, I've gathered as much. The fact that I can't is my gripe :) |
@waj any idea on why there are so many disconnections for localhost endpoints? |
@sardaukar you mean websockets are being disconnected with no apparent reason? Oh... from your example I can see the callback for the I think you need to put that loop into a separate fiber. I'd also collect all the open websockets in an array for example, and broadcast the |
@waj thanks, I'll try to work those in! Not sure what you mean by "the callback never returns", though. Still a noob :| |
@sardaukar I mean the block passed to |
Oh I see. Is there a better way to do it and still be able to react to a value coming in from a channel? I just need a different part of the code to signal the websocket handler to change the message and force a browser reload (with the accompanying JS script) |
@sardaukar maybe put that |
I fixed it with def run!
web_sockets = Set(HTTP::WebSocket).new
server = HTTP::Server.new([
HTTP::ErrorHandler.new,
HTTP::LogHandler.new,
HTTP::CompressHandler.new,
HTTP::WebSocketHandler.new do |ws, ctx|
spawn {
web_sockets << ws
ws.on_close do
web_sockets = web_sockets.delete(ws)
end
loop do
select
when msg = reload_channel.receive
web_sockets.each { |web_socket| web_socket.send("reload") }
when timeout(1.second)
web_sockets.each { |web_socket| web_socket.send("ping") }
end
end
}
end,
HTTP::StaticFileHandler.new("./output/", directory_listing: false),
]) do |context|
if is_html_index_request?(context)
context.response.status_code = 301
context.response.headers["Location"] = "#{context.request.path}index.html"
puts "\nRedirecting implicit HTML index request..." # TODO colorize
else
context.response.status_code = 404
STDERR.puts "\nFile not found!" # TODO colorize
end
end
address = server.bind_tcp(port)
puts "Listening on http://#{address}"
server.listen
end Using a |
@sardaukar I'd put the |
I have a local server for a static site generator I'm working on:
Another part of the code watches local Markdown files, and when one of them changes a value is sent to the
reload_channel
channel, and the WebSocket message sent to the client is changed fromping
toreload
and the browser reloads.This all works, but 15/20 seconds after getting the first reload on the browser, and without other values sent to
reload_channel
I get:On the browser (Firefox) I just get a skipped ping, and things go back to normal:
Since it's not too disruptive, I just wanted to
rescue
this error but I can't seem to do it even with abegin/rescue
on therun!
method for the class pasted above.Any pointers helpful!
My
crystal -v
output:The text was updated successfully, but these errors were encountered: