Repository: foundationdb/fdb-record-layer
Issue: The OnlineIndexerTest::closeWhileBuilding test sometimes hangs

I've seen the `OnlineIndexerTest::closeWhileBuilding` test hang a few times, possibly only when run on the CI server. There's presumably some timing issue, either with the test or with the code itself, that sometimes results in it waiting on a future that will never complete (if I had to guess). Either that, or its `whileTrue` loop is looping forever.

Changed files:
fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerBase.java
fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerTest.java

diff --git a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerBase.java b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerBase.java
index a336321b..4bdcbfd9 100644
--- a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerBase.java
+++ b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerBase.java
@@ -281,7 +281,12 @@ public class OnlineIndexerBase<M extends Message> implements AutoCloseable {
                             }
                         }
                     }
-                }).thenCompose(Function.identity()), runner.getExecutor());
+                }).thenCompose(Function.identity()), runner.getExecutor())
+                .whenComplete((vignore, e) -> {
+                    if (e != null) {
+                        ret.completeExceptionally(runner.getDatabase().mapAsyncToSyncException(e));
+                    }
+                });
 
         return ret;
     }
diff --git a/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerTest.java b/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerTest.java
index 222a846a..bcdd022a 100644
--- a/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerTest.java
+++ b/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerTest.java
@@ -84,6 +84,7 @@ import java.util.Set;
 import java.util.TreeSet;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CompletionException;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Function;
@@ -144,6 +145,7 @@ public class OnlineIndexerTest {
     public void setUp() {
         if (fdb == null) {
             fdb = FDBDatabaseFactory.instance().getDatabase();
+            fdb.setAsyncToSyncTimeout(5, TimeUnit.MINUTES);
         }
         if (subspace == null) {
             subspace = DirectoryLayer.getDefault().createOrOpen(fdb.database(), Arrays.asList("record-test", "unit", "oib")).join();
@@ -2206,7 +2208,7 @@ public class OnlineIndexerTest {
             recordStore.clearAndMarkIndexWriteOnly(index).join();
             context.commit();
         }
-        
+
         final FDBStoreTimer timer = new FDBStoreTimer();
         final CompletableFuture<Void> future;
         try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder()