Skip to content

Commit

Permalink
Minor update to IO client re-connect logic (openremote#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
richturner authored Jun 14, 2022
1 parent f33f4dd commit e6e5d53
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,13 @@ jobs:
timeout-minutes: 20
#continue-on-error: true

- name: Archive backend test results
if: always()
uses: actions/upload-artifact@v3
with:
name: backend-test-results
path: test/build/reports/tests

- name: Cleanup backend tests
if: ${{ steps.test-backend-command.outputs.value != '' && steps.test-ui-command.outputs.value != '' }}
run: ${{ steps.run-backend-tests.outputs.cleanup }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public abstract class AbstractNettyIOClient<T, U extends SocketAddress> implemen

public static long RECONNECT_DELAY_INITIAL_MILLIS = 1000L;
public static long RECONNECT_DELAY_MAX_MILLIS = 5*60000L;
public static long RECONNECT_DELAY_JITTER_MILLIS = 10000L;

/**
* This is intended to be used at the end of a decoder chain where the previous decoder outputs a {@link ByteBuf};
Expand Down Expand Up @@ -211,17 +210,15 @@ public void connect() {
onConnectionStatusChanged(ConnectionStatus.CONNECTING);
}

scheduleDoConnect(true);
scheduleDoConnect(false);
}

protected void scheduleDoConnect(boolean immediate) {
long jitter = immediate ? 50 : Math.max(50, RECONNECT_DELAY_JITTER_MILLIS);
long delay = immediate ? 50 : Math.max(50, RECONNECT_DELAY_INITIAL_MILLIS);
long maxDelay = immediate ? 51 : Math.max(delay+1, Math.max(50, RECONNECT_DELAY_MAX_MILLIS));
long delay = immediate ? 50 : Math.max(250, RECONNECT_DELAY_INITIAL_MILLIS);
long maxDelay = immediate ? 51 : Math.max(delay+1, Math.max(250, RECONNECT_DELAY_MAX_MILLIS));

RetryPolicy<Object> retryPolicy = RetryPolicy.builder()
.withJitter(Duration.ofMillis(jitter))
.withDelay(Duration.ofMillis(delay))
.withJitter(Duration.ofMillis(delay))
.withBackoff(Duration.ofMillis(delay), Duration.ofMillis(maxDelay))
.handle(RuntimeException.class)
.onRetryScheduled((execution) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ protected void doStart(Container container) throws Exception {
@Override
protected void doStop(Container container) throws Exception {
if (network != null) {
network.removeConnectionStatusConsumer(this::setConnectionStatus);
network.disconnect();
network.close();
network.removeConnectionStatusConsumer(this::setConnectionStatus);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ public ScheduledExecutorService getExecutorService() {
}

public void sendPackets(VelbusPacket... packets) {
if (getConnectionStatus() != ConnectionStatus.CONNECTED) {
return;
synchronized (this) {
if (getConnectionStatus() != ConnectionStatus.CONNECTED) {
return;
}
}

synchronized (messageQueue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class TestFixture implements IGlobalExtension {
public void start() {
// Force RECONNECT times to be short to improve test run times
AbstractNettyIOClient.RECONNECT_DELAY_INITIAL_MILLIS = 50;
AbstractNettyIOClient.RECONNECT_DELAY_JITTER_MILLIS = 0;
AbstractNettyIOClient.RECONNECT_DELAY_MAX_MILLIS = 50;
}

Expand Down

0 comments on commit e6e5d53

Please sign in to comment.