Closed PeterRunich closed 1 year ago
I will review your issue, however at first glance, isn't this wrong?
rescue
connection.close
shouldn't it be ensure
?
Сode in rescue block is executed. The idea is that on the server I close the connection with an error, I catch all errors, even though I could use Async::WebSocket::ProtocolError, but then it won't catch the error, because it throws Errno::EPIPE: Broken pipe.
require 'async'
require 'async/websocket'
require 'async/http'
Async do |task|
begin
endpoint = Async::HTTP::Endpoint.parse 'ws://localhost:7070/'
connection = Async::WebSocket::Client.connect endpoint
connection.read
rescue Async::WebSocket::ProtocolError => e
p e.code
connection.close
end
p task.print_hierarchy
end
| Task may have ended with unhandled exception.
| Errno::EPIPE: Broken pipe
| → /home/pepe/.rbenv/versions/3.2.0/lib/ruby/3.2.0/socket.rb:460 in `__write_nonblock'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/3.2.0/socket.rb:460 in `write_nonblock'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-io-1.34.0/lib/async/io/generic.rb:216 in `async_send'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-io-1.34.0/lib/async/io/generic.rb:62 in `block in wrap_blocking_method'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-io-1.34.0/lib/async/io/generic.rb:156 in `write'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-io-1.34.0/lib/async/io/stream.rb:160 in `block in flush'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-2.3.1/lib/async/semaphore.rb:68 in `acquire'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-io-1.34.0/lib/async/io/stream.rb:155 in `flush'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/framer.rb:57 in `flush'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/connection.rb:68 in `flush'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/connection.rb:207 in `send_close'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/connection.rb:96 in `rescue in read_frame'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/connection.rb:81 in `read_frame'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/connection.rb:237 in `read'
| main.rb:142 in `block in <main>'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-2.3.1/lib/async/task.rb:107 in `block in run'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-2.3.1/lib/async/task.rb:248 in `block in schedule'
| Caused by Protocol::WebSocket::ClosedError:
| → /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/connection.rb:143 in `receive_close'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/close_frame.rb:70 in `apply'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/connection.rb:92 in `read_frame'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/protocol-websocket-0.9.1/lib/protocol/websocket/connection.rb:237 in `read'
| main.rb:142 in `block in <main>'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-2.3.1/lib/async/task.rb:107 in `block in run'
| /home/pepe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/async-2.3.1/lib/async/task.rb:248 in `block in schedule'
@ioquatix if there’s anything I can do to help, let me know.
Can you please test out the latest version and confirm the issue is fixed? Thanks!
Yep, it works as i expected, thanks for review and async gem!
I use this server for testing
After printing tasks hierarchy i got this
i expect that Async::Pool::Controller Gardener task was gone after connection.close, but it there
i do some fix and seems it works https://github.com/socketry/async-websocket/pull/45
Is the behavior in the original considered okay? If "yes", can you explain why?