mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
Networking: bump default connect timeout to 5 seconds.
Improve some logging.
This commit is contained in:
parent
1f37350161
commit
aaa539bd80
@ -179,7 +179,7 @@ public class PeerGroup extends AbstractIdleService implements TransactionBroadca
|
||||
private int lastBloomFilterElementCount;
|
||||
|
||||
/** The default timeout between when a connection attempt begins and version message exchange completes */
|
||||
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 2000;
|
||||
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 5000;
|
||||
private volatile int vConnectTimeoutMillis = DEFAULT_CONNECT_TIMEOUT_MILLIS;
|
||||
|
||||
/**
|
||||
|
@ -16,14 +16,6 @@
|
||||
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.NotYetConnectedException;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import com.google.bitcoin.net.AbstractTimeoutHandler;
|
||||
import com.google.bitcoin.net.MessageWriteTarget;
|
||||
import com.google.bitcoin.net.StreamParser;
|
||||
@ -32,9 +24,16 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.NotYetConnectedException;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
|
||||
/**
|
||||
* Handles high-level message (de)serialization for peers, acting as the bridge between the
|
||||
@ -109,6 +108,7 @@ public abstract class PeerSocketHandler extends AbstractTimeoutHandler implement
|
||||
|
||||
@Override
|
||||
protected void timeoutOccurred() {
|
||||
log.info("{}: Timed out", getAddress());
|
||||
close();
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ package com.google.bitcoin.net;
|
||||
|
||||
import com.google.bitcoin.core.Message;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.base.Throwables;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
@ -222,7 +223,7 @@ class ConnectionHandler implements MessageWriteTarget {
|
||||
} catch (Exception e) {
|
||||
// This can happen eg if the channel closes while the thread is about to get killed
|
||||
// (ClosedByInterruptException), or if handler.parser.receiveBytes throws something
|
||||
log.error("Error handling SelectionKey: ", e);
|
||||
log.error("Error handling SelectionKey: {}", Throwables.getRootCause(e).getMessage());
|
||||
handler.closeConnection();
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.google.bitcoin.net;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.util.concurrent.AbstractExecutionThreadService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -62,13 +63,11 @@ public class NioClientManager extends AbstractExecutionThreadService implements
|
||||
log.error("Failed to connect to {}", sc.socket().getRemoteSocketAddress());
|
||||
handler.closeConnection(); // Failed to connect for some reason
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
// If e is a CancelledKeyException, there is a race to get to interestOps after finishConnect() which
|
||||
// may cause this. Otherwise it may be any arbitrary kind of connection failure.
|
||||
// Calling sc.socket().getRemoteSocketAddress() here throws an exception, so we can only log the error itself
|
||||
log.error("Failed to connect with exception: {}", e.getMessage());
|
||||
handler.closeConnection();
|
||||
} catch (CancelledKeyException e) { // There is a race to get to interestOps after finishConnect() which may cause this
|
||||
// Calling sc.socket().getRemoteSocketAddress() here throws an exception, so we can only log the error itself
|
||||
log.error("Failed to connect with exception: {}", e.getMessage());
|
||||
log.error("Failed to connect with exception: {}", Throwables.getRootCause(e).getMessage());
|
||||
handler.closeConnection();
|
||||
}
|
||||
} else // Process bytes read
|
||||
|
Loading…
x
Reference in New Issue
Block a user