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

Pusher Error codes are not handled #40

Open
tacticiankerala opened this issue Apr 14, 2014 · 6 comments
Open

Pusher Error codes are not handled #40

tacticiankerala opened this issue Apr 14, 2014 · 6 comments

Comments

@tacticiankerala
Copy link

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

  • 4000-4099: The connection SHOULD NOT be re-established unchanged.
  • 4100-4199: The connection SHOULD be re-established after backing off. The back-off time SHOULD be at least 1 second in duration and MAY be exponential in nature on consecutive failures.
  • 4200-4299: The connection SHOULD be re-established immediately.

The following is how it is handled in the library:

bind('pusher:error') do |data|
        PusherClient.logger.fatal("Pusher : error : #{data.inspect}")
 end

This is resulting in infinite loop that logs "end of file reached", when pusher closes the connection with the error code 4200.

@zimbatm
Copy link
Contributor

zimbatm commented Apr 14, 2014

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.

@tacticiankerala
Copy link
Author

+1
We are also working on that.

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.

@zimbatm
Copy link
Contributor

zimbatm commented Apr 14, 2014

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

@zimbatm
Copy link
Contributor

zimbatm commented May 22, 2014

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.

@nqtien310
Copy link

Hi all,
Seems like this error isn't completely solved yet, I faced it couple of times the last few weeks. this is the errors output
...
end of file reached
end of file reached
end of file reached
...

I tried to reproduce it by triggering error inside the loop of PusherClient::Socket#connection_internal, and here's the output
...
Pusher : error : "Error message"
Pusher : event received : channel: ; event: pusher:error
Dispatching global callbacks for pusher:error
Pusher : error : "Error message"
Pusher : event received : channel: ; event: pusher:error
Dispatching global callbacks for pusher:error
...

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

@vimalvnair
Copy link

We fixed this issue (infinite loop that logs 'end of file reached') by doing the following hack in our code:

Note: We are using pusher-client v0.4.0. So this hack will not work in the newer versions.

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

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

No branches or pull requests

4 participants