From ffabd4eaa32c886c4a5fc072420a1f7738ce7258 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Mon, 31 Dec 2018 16:24:51 +0100
Subject: [PATCH] [fix] When adding a execution action, make sure the ppol
 accepted it. Avoid execution lost

---
 .../client/Duniter4jClientImpl.java           | 33 ++++++++++---------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/client/Duniter4jClientImpl.java b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/client/Duniter4jClientImpl.java
index 5bed8bd6..46dd607b 100644
--- a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/client/Duniter4jClientImpl.java
+++ b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/client/Duniter4jClientImpl.java
@@ -1074,25 +1074,26 @@ public class Duniter4jClientImpl implements Duniter4jClient {
 
     public void safeExecuteRequest(ActionRequestBuilder<?, ?, ?> request, boolean wait) {
         // Execute in a pool
-        if (!wait) {
-            boolean acceptedInPool = false;
-            while(!acceptedInPool)
+        ListenableActionFuture<?> actionFuture = null;
+        boolean acceptedInPool = false;
+        while(!acceptedInPool) {
+            try {
+                actionFuture = request.execute();
+                acceptedInPool = true;
+            }
+            catch(EsRejectedExecutionException e) {
+                // not accepted, so wait
                 try {
-                    request.execute();
-                    acceptedInPool = true;
+                    Thread.sleep(1000); // 1s
                 }
-                catch(EsRejectedExecutionException e) {
-                    // not accepted, so wait
-                    try {
-                        Thread.sleep(1000); // 1s
-                    }
-                    catch(InterruptedException e2) {
-                        // silent
-                    }
+                catch(InterruptedException e2) {
+                    // silent
                 }
-
-        } else {
-            request.execute().actionGet();
+            }
+        }
+        // Wait end of action, if need
+        if (wait && actionFuture != null) {
+            actionFuture.actionGet();
         }
     }
 }
-- 
GitLab