From beeca445a9e39adf091c969721fecaee0a8556fa Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Fri, 13 Dec 2024 15:19:10 +1100 Subject: [PATCH] 7582: Put AbstractSyncTargetManager.waitForPeerAndThenSetSyncTarget code back separate thread to avoid infinite loop waiting for peers during acceptance tests Signed-off-by: Matilda Clerke --- .../eth/sync/AbstractSyncTargetManager.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/AbstractSyncTargetManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/AbstractSyncTargetManager.java index e21bec81e40..46d9aed20a4 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/AbstractSyncTargetManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/AbstractSyncTargetManager.java @@ -24,9 +24,9 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.plugin.services.MetricsSystem; +import java.time.Duration; import java.util.Optional; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.slf4j.Logger; @@ -117,10 +117,15 @@ protected Optional finalizeSelectedSyncTarget(final SyncTarget syncT private CompletableFuture waitForPeerAndThenSetSyncTarget() { return ethContext - .getEthPeers() - .waitForPeer((peer) -> true) - .orTimeout(5, TimeUnit.SECONDS) - .thenCompose((r) -> findSyncTarget()); + .getScheduler() + .scheduleFutureTask( + () -> + ethContext + .getEthPeers() + .waitForPeer((peer) -> true) + .handle((ignored, ignored2) -> null) + .thenCompose((r) -> findSyncTarget()), + Duration.ofSeconds(5)); } private boolean isCancelled() {