diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java
index f1468d0fe9bcc..d7d67b3af159e 100644
--- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java
+++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java
@@ -1402,7 +1402,7 @@ public boolean flush(FlushRequest request) {
      * Executes the given flush request against the engine.
      *
      * @param request the flush request
-     * @param listener to notify after fully durability has been achieved.
+     * @param listener to notify after full durability has been achieved.
      *                 <code>false</code> if <code>waitIfOngoing==false</code>
      *                 and an ongoing request is detected, else <code>true</code>.
      *                 If <code>false</code> is returned, no flush happened.
@@ -3787,8 +3787,8 @@ public void onFailure(Exception e) {
                                 }
                             }
                         });
-                        afterWriteOperation();
                         flushOrRollRunning.compareAndSet(true, false);
+                        afterWriteOperation();
                     });
                 } else if (shouldRollTranslogGeneration()) {
                     logger.debug("submitting async roll translog generation request");