Improved disconnect process - try 5 times before force close session

This commit is contained in:
Volodymyr Babak 2021-04-09 19:53:46 +03:00
parent 770d3f91f2
commit c5f5acdba1

View File

@ -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());
}
}