Skip to content

Conversation

@marregui
Copy link
Contributor

card: https://hivemq.kanbanize.com/ctrl_board/57/cards/38362/details/

  • Removed hardcoded KEEP_ALIVE_TIMEOUT_MS = 30_000
  • Added a new public method getKeepAliveTimeoutMs() that computes the timeout dynamically using the formula:
    keepAliveIntervalMs × (keepAliveFailuresAllowed + 1) + 5000ms (safety margin)
  • Updated isKeepAliveHealthy() to use the dynamically computed timeout

Formula Explanation

With default ConnectionOptions:

  • keepAliveIntervalMs = 10,000ms (10 seconds)
  • keepAliveFailuresAllowed = 3
  • Safety margin = 5,000ms

Result: 10,000 × (3 + 1) + 5,000 = 45,000ms (45 seconds)

This is more appropriate than the previous hardcoded 30 seconds because:

  • The OPC UA client allows 3 failures before considering the connection dead
  • With a 10-second keep-alive interval, worst case is 30 seconds before failure detection
  • The extra interval + safety margin prevents false positives

…veIntervalMs() * (connOpts.keepAliveFailuresAllowed() + 1) + 5_000L instead of the hardcoded 30 seconds, which exactly matched by chance keepAliveIntervalMs * keepAliveFailuresAllowed
@marregui marregui self-assigned this Nov 27, 2025
@cla-bot cla-bot bot added the cla-signed label Nov 27, 2025
Copy link
Member

@caoccao caoccao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

*/
public long getKeepAliveTimeoutMs() {
final var connOpts = config.getConnectionOptions();
return connOpts.keepAliveIntervalMs() * (connOpts.keepAliveFailuresAllowed() + 1) + 5_000L;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we give a name to that magic number?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants