-
Notifications
You must be signed in to change notification settings - Fork 61
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
Pusher Error codes are not handled #40
Comments
Thanks for the great feedback. The client library needs more work for sure. I made a pass two weeks ago but it's not enough. We have planned more work during this quarter so hopefully I'll be able to come back to that. |
+1 Any idea how can I trigger pusher error codes so that I can test it thoroughly ? I have raised a support ticket in pusher for the same. |
Nice. I would augment the mock connection to return the error codes that you want: https://github.com/pusher/pusher-ruby-client/blob/master/spec/spec_helper.rb |
Just pushed a couple of fixes on master. Thought you might want to know in case you're still working on those improvements you where talking about. |
Hi all, I tried to reproduce it by triggering error inside the loop of PusherClient::Socket#connection_internal, and here's the output As you can see there's the difference between 2 errors output, the latter one has more detail than the actual one, seem like there's some error within PusherClient::Socket#connection_internal which is not handle properly in Ruby-Client |
We fixed this issue (infinite loop that logs 'end of file reached') by doing the following hack in our code:
Note: We are using Here is the code for hack: require 'pusher-client'
module PusherClient
class PusherWebSocket
def receive
raise "no handshake!" unless @handshaked
begin
data = @socket.read_nonblock(1024)
rescue *WAIT_EXCEPTIONS
IO.select([@socket])
retry
end
@frame << data
messages = []
while message = @frame.next
if message.type === :ping
send(message.data, :pong)
return messages
end
messages << message.to_s
end
messages
end
end
class Socket
def connect(async = false)
if @encrypted
url = "wss://#{@ws_host}:#{@wss_port}#{@path}"
else
url = "ws://#{@ws_host}:#{@ws_port}#{@path}"
end
PusherClient.logger.debug("Pusher : connecting : #{url}")
@connection_thread = Thread.new {
options = {:ssl => @encrypted, :cert_file => @cert_file, :ssl_verify => @ssl_verify}
@connection = PusherWebSocket.new(url, options)
PusherClient.logger.debug "Websocket connected"
begin
loop do
msg = @connection.receive[0]
next if msg.nil?
params = parser(msg)
next if params['socket_id'] && params['socket_id'] == self.socket_id
send_local_event params['event'], params['data'], params['channel']
end
rescue Exception => error
PusherClient.logger.error "Pusher Exception Handler"
PusherClient.logger.error error.message
disconnect
end
}
@connection_thread.run
@connection_thread.join unless async
self
end
end
end |
I found the following in the pusher documentation and also found that the library is not handling the same.
Connection closure
Clients may close the WebSocket connection at any time.
The Pusher server may choose to close the WebSocket connection, in which case a close code and reason will be sent.
Clients SHOULD support the following 3 ranges
The following is how it is handled in the library:
This is resulting in infinite loop that logs "end of file reached", when pusher closes the connection with the error code 4200.
The text was updated successfully, but these errors were encountered: