Skip to content

Pick up DNS changes #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@
*/
public abstract class AbstractEndpoint extends AbstractStateMachine<LifecycleState> implements Endpoint {

/**
* A flag which controls whether the endpoint should force a DNS lookup request for the provided
* hostname in case the socket get disconnect.
*/
protected static final boolean FORCE_DNS_LOOKUP_ON_RECONNECT = Boolean.parseBoolean(
System.getProperty("com.couchbase.forceDnsLookupOnReconnect", "false")
);

/**
* The logger used.
*/
Expand All @@ -116,7 +124,7 @@ public abstract class AbstractEndpoint extends AbstractStateMachine<LifecycleSta
/**
* The netty bootstrap adapter.
*/
private final BootstrapAdapter bootstrap;
private volatile BootstrapAdapter bootstrap;

/**
* The name of the couchbase bucket (needed for bucket-level endpoints).
Expand Down Expand Up @@ -271,7 +279,10 @@ protected AbstractEndpoint(final String hostname, final String bucket, final Str
LOGGER.debug("Using a connectCallbackGracePeriod of {} on Endpoint {}:{}", connectCallbackGracePeriod,
hostname, port);
this.sslEngineFactory = env.sslEnabled() ? new SSLEngineFactory(env) : null;
bootstrap = createBootstrap(hostname, port);
}

private BootstrapAdapter createBootstrap(String hostname, int port) {
Class<? extends Channel> channelClass = NioSocketChannel.class;
if (ioPool instanceof EpollEventLoopGroup) {
channelClass = EpollSocketChannel.class;
Expand All @@ -283,7 +294,7 @@ protected AbstractEndpoint(final String hostname, final String bucket, final Str
? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT;

boolean tcpNodelay = environment().tcpNodelayEnabled();
bootstrap = new BootstrapAdapter(new Bootstrap()
return new BootstrapAdapter(new Bootstrap()
.remoteAddress(hostname, port)
.group(ioPool)
.channel(channelClass)
Expand Down Expand Up @@ -489,6 +500,9 @@ public void run() {
// the disconnect phase. If this happens, explicitly break the retry loop
// and re-run the disconnect phase to make sure all is properly freed.
if (!disconnected) {
if (FORCE_DNS_LOOKUP_ON_RECONNECT) {
bootstrap = createBootstrap(hostname, port);
}
doConnect(observable, bootstrapping);
} else {
LOGGER.debug("{}Explicitly breaking retry loop because already disconnected.",
Expand Down