Commit c5f5acdba118fc576e73badbd2432145b0901203
1 parent
770d3f91
Improved disconnect process - try 5 times before force close session
Showing
1 changed file
with
22 additions
and
2 deletions
@@ -154,10 +154,30 @@ public class EdgeGrpcClient implements EdgeRpcClient { | @@ -154,10 +154,30 @@ public class EdgeGrpcClient implements EdgeRpcClient { | ||
154 | if (!onError) { | 154 | if (!onError) { |
155 | try { | 155 | try { |
156 | inputStream.onCompleted(); | 156 | inputStream.onCompleted(); |
157 | - } catch (Exception ignored) {} | 157 | + } catch (Exception e) { |
158 | + log.error("Exception during onCompleted", e); | ||
159 | + } | ||
158 | } | 160 | } |
159 | if (channel != null) { | 161 | if (channel != null) { |
160 | - channel.shutdown().awaitTermination(timeoutSecs, TimeUnit.SECONDS); | 162 | + channel.shutdown(); |
163 | + int attempt = 0; | ||
164 | + do { | ||
165 | + try { | ||
166 | + channel.awaitTermination(timeoutSecs, TimeUnit.SECONDS); | ||
167 | + } catch (Exception e) { | ||
168 | + log.error("Channel await termination was interrupted", e); | ||
169 | + } | ||
170 | + if (attempt > 5) { | ||
171 | + log.warn("We had reached maximum of termination attempts. Force closing channel"); | ||
172 | + try { | ||
173 | + channel.shutdownNow(); | ||
174 | + } catch (Exception e) { | ||
175 | + log.error("Exception during shutdownNow", e); | ||
176 | + } | ||
177 | + break; | ||
178 | + } | ||
179 | + attempt++; | ||
180 | + } while (!channel.isTerminated()); | ||
161 | } | 181 | } |
162 | } | 182 | } |
163 | 183 |