Browse Source

Improved disconnect process - try 5 times before force close session

pull/3811/head
Volodymyr Babak 5 years ago
parent
commit
c5f5acdba1
  1. 24
      common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java

24
common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java

@ -154,10 +154,30 @@ public class EdgeGrpcClient implements EdgeRpcClient {
if (!onError) {
try {
inputStream.onCompleted();
} catch (Exception ignored) {}
} catch (Exception e) {
log.error("Exception during onCompleted", e);
}
}
if (channel != null) {
channel.shutdown().awaitTermination(timeoutSecs, TimeUnit.SECONDS);
channel.shutdown();
int attempt = 0;
do {
try {
channel.awaitTermination(timeoutSecs, TimeUnit.SECONDS);
} catch (Exception e) {
log.error("Channel await termination was interrupted", e);
}
if (attempt > 5) {
log.warn("We had reached maximum of termination attempts. Force closing channel");
try {
channel.shutdownNow();
} catch (Exception e) {
log.error("Exception during shutdownNow", e);
}
break;
}
attempt++;
} while (!channel.isTerminated());
}
}

Loading…
Cancel
Save