diff --git a/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java b/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java index 5ee2f3341f..f974cb9598 100644 --- a/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java +++ b/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java @@ -79,6 +79,7 @@ public class EdgeGrpcClient implements EdgeRpcClient { throw new RuntimeException(e); } } + gracefulShutdown(); channel = builder.build(); EdgeRpcServiceGrpc.EdgeRpcServiceStub stub = EdgeRpcServiceGrpc.newStub(channel); log.info("[{}] Sending a connect request to the TB!", edgeKey); @@ -89,6 +90,16 @@ public class EdgeGrpcClient implements EdgeRpcClient { .build()); } + private void gracefulShutdown() { + try { + if (channel != null) { + channel.shutdown().awaitTermination(timeoutSecs, TimeUnit.SECONDS); + } + } catch (InterruptedException e) { + log.debug("Error during shutdown of the previous channel", e); + } + } + @Override public void disconnect() throws InterruptedException { inputStream.onCompleted();