Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Disconnect / Reconnect Process and Error Messages

Tags:

pusher

I am trying to implement a feature which notifies the user of disconnections to pusher, and indicates when reconnection has occured. My first experiment is simply to log changing pusher states to console:

var pusher = new Pusher('MY_ACCOUNT_STRING');
pusher.connection.bind('state_change', function(states) {
  console.log(states.current);
});

I then refresh the page, get a connection to pusher, disable my internet connection, wait for pusher to detect the disconnection, re-enable my internet connection, and wait for pusher to detect that. Here's a screenshot of chrome's console output during the process (click here for a larger version):

chrome console during disconnection

Here are my questions:

  1. It took over a minute, possibly even 2-3 minutes, before the disconnection was detected by pusher. Is there a way to decrease that time so pusher detects disconnection within 10 or so seconds?
  2. Why am I seeing those red errors, and what exactly do they mean? Is that normal? I would think with the correct setup the errors would be handled, since a disconnection event is an "expected" exception within the pusher context.
  3. What is the 1006 error and why am I seeing that?

Thanks for any help!

EDIT:

I've been watching the output for a long-standing connection, and I've also seen this a number of times, and would like to know the cause of it, and how I can capture it and handle it?

disconnected login.js:146
connecting login.js:146
Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":1007,"message":"Server heartbeat missed"}}} pusher.min.js:12
connected 
like image 898
Jonah Avatar asked Oct 21 '22 02:10

Jonah


1 Answers

That's no normal behavior. Have you had the chance to check this on different machine and network? It looks like a network problem.

Question 1.

When I disable wifi it takes pusher 4 seconds to notice and change the state to disconnected and then to unavailable.

When I re-enable wifi I only get same error as you do on http://js.pusher.com/2.1.3/sockjs.js

I've got no idea about the implications of doing so.. but you could try to alter the default timeouts:

var pusher = new Pusher('MY_ACCOUNT_STRING',  {
    pong_timeout: 6000, //default = 30000
    unavailable_timeout: 2000 //default = 10000
});

Question 2.

No idea, I don't think the lib should throw those error's

Question 3.

The error's are from the WebSocket protocol: https://www.rfc-editor.org/rfc/rfc6455

  1006 is a reserved value and MUST NOT be set as a status code in a
  Close control frame by an endpoint.  It is designated for use in
  applications expecting a status code to indicate that the
  connection was closed abnormally, e.g., without sending or
  receiving a Close control frame.

  1007 indicates that an endpoint is terminating the connection
  because it has received data within a message that was not
  consistent with the type of the message (e.g., non-UTF-8 [RFC3629]
  data within a text message).
like image 153
Tieme Avatar answered Jan 02 '23 20:01

Tieme