-
Notifications
You must be signed in to change notification settings - Fork 38
fix: Add OPCUA Auto-reconnect Retry Backoff Strategy #1304
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
base: master
Are you sure you want to change the base?
Conversation
marregui
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
...emq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/OpcUaProtocolAdapter.java
Show resolved
Hide resolved
| } | ||
|
|
||
| final double backoffDelay = | ||
| backoffDelays[index] * (1 + new Random().nextDouble(ConnectionOptions.DEFAULT_RETRY_JITTER)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a new random object per retry seems excessive, why not use ThreadLocalRandom.current()
| final long retryIntervalMs = config.getConnectionOptions().retryIntervalMs(); | ||
| // Increment retry attempt counter and calculate backoff delay | ||
| final int attemptCount = consecutiveRetryAttempts.updateAndGet(count -> count + 1); | ||
| long backoffDelayMs ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the extra space before the ; killed my day
| @ModuleConfigField(title = "Connection Retry Intervals (milliseconds)", | ||
| description = "Comma-separated list of backoff delays in milliseconds for connection retry attempts. The adapter will use these delays sequentially for each retry attempt, repeating the last value if attempts exceed the list length.", | ||
| defaultValue = DEFAULT_RETRY_INTERVALS) | ||
| String retryIntervalMs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change from Long to String..... radical, I hope it does not break existing config?
| private final @NotNull AtomicReference<ScheduledFuture<?>> healthCheckFuture = new AtomicReference<>(); | ||
|
|
||
| // Retry attempt tracking for exponential backoff | ||
| private final @NotNull AtomicReference<Integer> consecutiveRetryAttempts = new AtomicReference<>(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AtomicInteger is more compact than an AtomicReference to an Integer (and more efficient)
791b828 to
b33caf4
Compare
marregui
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
https://hivemq.kanbanize.com/ctrl_board/57/cards/38364/details/