From 3ef81894c65594a0084075aac631bbba61ae86a3 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 4 Aug 2021 20:03:58 +0300 Subject: [PATCH] Executors and connection close on statistics sent event --- .../service/statistics/StatisticsClient.java | 12 +++--------- .../service/statistics/StatisticsService.java | 6 +++++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/epam/reportportal/service/statistics/StatisticsClient.java b/src/main/java/com/epam/reportportal/service/statistics/StatisticsClient.java index 0ce918a3..b268373c 100644 --- a/src/main/java/com/epam/reportportal/service/statistics/StatisticsClient.java +++ b/src/main/java/com/epam/reportportal/service/statistics/StatisticsClient.java @@ -175,15 +175,6 @@ private Map buildPostRequest(StatisticsItem item) { @Override public void close() { - ofNullable(executor).ifPresent(e -> { - e.shutdown(); - try { - if (!e.awaitTermination(10, TimeUnit.SECONDS)) { - e.shutdownNow(); - } - } catch (InterruptedException ignore) { - } - }); ofNullable(httpClient).ifPresent(c -> { ExecutorService e = c.dispatcher().executorService(); e.shutdown(); @@ -195,5 +186,8 @@ public void close() { } c.connectionPool().evictAll(); }); + httpClient = null; + ofNullable(executor).ifPresent(ExecutorService::shutdownNow); + executor = null; } } diff --git a/src/main/java/com/epam/reportportal/service/statistics/StatisticsService.java b/src/main/java/com/epam/reportportal/service/statistics/StatisticsService.java index 29cc0537..f6ebfe69 100644 --- a/src/main/java/com/epam/reportportal/service/statistics/StatisticsService.java +++ b/src/main/java/com/epam/reportportal/service/statistics/StatisticsService.java @@ -104,7 +104,11 @@ public void sendEvent(Maybe launchIdMaybe, StartLaunchRQ rq) { //noinspection ResultOfMethodCallIgnored statisticsMaybe.subscribe(t -> { ofNullable(t.body()).ifPresent(ResponseBody::close); - }, t -> LOGGER.error("Unable to send statistics", t)); + getStatistics().close(); + }, t -> { + LOGGER.error("Unable to send statistics", t); + getStatistics().close(); + }); } @Override