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

Autoping_interval and autoping_timeout are not being set to provided values #507

Open
rowlowles opened this issue May 1, 2020 · 1 comment

Comments

@rowlowles
Copy link

Summary:

I noted that it appears that options.autoping_interval and options.autoping_timeout are not being set in websocket.js.

Reproduction:

This was noticed when I was setting up a simple implementation of Autobahn. I provided the following arguments to autobahn.Connection:

{
  "max_retries": -1,
  "max_retry_delay": 30,
  "autoping_interval": 100,
  "autoping_timeout": 100,
  "url": "{my_websocket_url_here}",
  "realm": "default"
}

Using my debugger I confirmed that self._options was being set to the above object. Then, in transportwebsocket.js I noted that the options.autoping_interval and options.autoping_timeout values were not defined and that they were set to the defaults of 10 seconds and 5 seconds respectively.

To test this out, I turned off WiFi on my computer, to simulate a situation where the Heartbeat should notice when the network failed. Rather than taking 200 seconds to notice the connection had died, the onclose handler was being called after 15 seconds with reason === 'lost'.

Environment:

Autobahn Version: Tested on 20.4.1, and 18.10.2
Node: 10.16.0

@ljluestc
Copy link

const autobahn = require('autobahn');

const connection = new autobahn.Connection({
  url: '{my_websocket_url_here}',
  realm: 'default',
  max_retries: -1,
  max_retry_delay: 30,
});

// Manually set autoping options
const autopingInterval = 100;
const autopingTimeout = 100;

// Custom ping-pong logic
connection.onopen = (session) => {
  const pingInterval = setInterval(() => {
    session.ping('ping').catch(() => {
      // Handle ping failure
      clearInterval(pingInterval);
      connection.close();
    });
  }, autopingInterval);

  session.onpong = () => {
    // Pong received, connection is still alive
  };

  // Set a timeout for detecting connection loss
  const timeout = setTimeout(() => {
    clearInterval(pingInterval);
    connection.close();
  }, autopingTimeout);

  session.onclose = (reason) => {
    clearInterval(pingInterval);
    clearTimeout(timeout);
    // Handle connection closure
  };
};

connection.open();

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