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

Stale connection goes undetected in pusher-js 1.12 #28

Closed
videodesk opened this issue Nov 21, 2012 · 2 comments
Closed

Stale connection goes undetected in pusher-js 1.12 #28

videodesk opened this issue Nov 21, 2012 · 2 comments

Comments

@videodesk
Copy link

Hi,

I'm doing tests with this code:

<!DOCTYPE html>
<head>
  <title>Pusher Test</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
  <script src="http://js.pusher.com/1.12/pusher.min.js" type="text/javascript"></script>
<script type="text/javascript">
  $(document).ready(function() {
  Pusher.activity_timeout = 500;
  Pusher.pong_timeout = 500;
    var status = function(st) {
      $('#status').text(st);
    }
    // Enable pusher logging - don't include this in production
    Pusher.log = function(message) {
      if (window.console && window.console.log) window.console.log(message);
    };
    // Flash fallback logging - don't include this in production
    WEB_SOCKET_DEBUG = true;
Pusher.channel_auth_endpoint = '/app_dev.php/pusher/auth/';
    var pusher = new Pusher('MY_KEY', { encrypted: true });
    var channel = pusher.subscribe('presence-test_channel');
    channel.bind('my_event', function(data) {
      alert(data);
    });
      pusher.connection.bind('state_change', function(state) {
        status(state.current)
      })
      pusher.connection.bind('state_change', function(state) {
        status(state.current)
      })
  })
</script>
</head>
<body>
  Connection status: <strong><span id="status">unloaded</span></strong>
</body>
</html>

When I run this code, in the debug console on pusher, everything is fine: the client connects and subscribes to the presence-channel. But if I unplug my ethernet / close my laptop's lid / turn off wifi, there is no disconnection message in the debug console, even after a few minutes. I tried setting Pusher.activity_timeout and Pusher.pong_timeout to very low values (500 as you can see) but it doesn't help.
In my browser's javascript console, I can see ping/pong messages being sent. When I cut the connection, it doesn't seem to bother the server that much. Even though my webpage now reads "unavailable" (I print the current status connection).

I'm using Chrome (last release), OSX ML, Pusher 1.12. Same bug appears with firefox (last release) and safari.

@tillify
Copy link

tillify commented Mar 6, 2013

This is because the netinfo, offline online class that is used to detect when Pusher thinks the connection is on and online uses the browser bases navigator online offline event system. This is not reliable and does not detect the connection. In order for you app to work smoothly you can build your own online offline solution. The best approach to use your existing xhttp requests in your app to do it for you. When a request fails make a reliable ping to your server if that fails your app is offline, or your server is. In both cases your app is classified offline. You then need a delay ping to retry your service at intervals 5s,10s,25s,60s to reconnect. At which point an connection event can be hooked into pusher so that it reconnects

@pl
Copy link
Contributor

pl commented Jul 18, 2013

We're not going to work on reliability of 1.x, since that was the focus of 2.x. Switching to 2.1 should be painless and will improve connectivity dramatically. I don't think this issue was related to netinfo, though there are other problems it causes. We'll be reviewing online/offline detection soon.

@pl pl closed this as completed Jul 18, 2013
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

2 participants