mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
TransactionBroadcast: allow interrupt in dropPeerAfterBroadcastHandler()
If an `InterruptedException` occurs while sleeping in `dropPeerAfterBroadcastHandler()`, close the peer immediately instead of delaying the exception to preserve a full 1-second delay. Peers/PeerGroups can be shut down, and they should shut down as quickly as possible.
This commit is contained in:
parent
b959b7bdfb
commit
f190f589e6
1 changed files with 6 additions and 3 deletions
|
@ -17,7 +17,6 @@
|
||||||
package org.bitcoinj.core;
|
package org.bitcoinj.core;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.util.concurrent.Uninterruptibles;
|
|
||||||
import org.bitcoinj.base.internal.FutureUtils;
|
import org.bitcoinj.base.internal.FutureUtils;
|
||||||
import org.bitcoinj.base.internal.StreamUtils;
|
import org.bitcoinj.base.internal.StreamUtils;
|
||||||
import org.bitcoinj.base.internal.InternalUtils;
|
import org.bitcoinj.base.internal.InternalUtils;
|
||||||
|
@ -29,6 +28,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -37,7 +37,6 @@ import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static org.bitcoinj.base.internal.Preconditions.checkState;
|
import static org.bitcoinj.base.internal.Preconditions.checkState;
|
||||||
|
@ -272,7 +271,11 @@ public class TransactionBroadcast {
|
||||||
|
|
||||||
private static Runnable dropPeerAfterBroadcastHandler(Peer peer) {
|
private static Runnable dropPeerAfterBroadcastHandler(Peer peer) {
|
||||||
return () -> {
|
return () -> {
|
||||||
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
|
try {
|
||||||
|
Thread.sleep(Duration.ofSeconds(1).toMillis());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.warn("Sleep before drop-peer-after-broadcast interrupted. Peer will be closed now.");
|
||||||
|
}
|
||||||
peer.close();
|
peer.close();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue