[#3297] Fix race while resolve remote address that can cause NPE

Motivation:

We may produce a NPE due a race that can happen while check if a resolution was done and failed.

Modifications:

Correctly first check if the resultion is done before try to detect if it failed and so remove the race that can produce a NPE.

Result:

No more race possible while resolve address during connect.
This commit is contained in:
Norman Maurer 2016-05-02 14:50:42 +02:00
parent 2b65258568
commit c745ac0e16

View File

@ -172,15 +172,16 @@ public class Bootstrap extends AbstractBootstrap<Bootstrap, Channel> {
} }
final Future<SocketAddress> resolveFuture = resolver.resolve(remoteAddress); final Future<SocketAddress> resolveFuture = resolver.resolve(remoteAddress);
final Throwable resolveFailureCause = resolveFuture.cause();
if (resolveFailureCause != null) {
// Failed to resolve immediately
channel.close();
return channel.newFailedFuture(resolveFailureCause);
}
if (resolveFuture.isDone()) { if (resolveFuture.isDone()) {
final Throwable resolveFailureCause = resolveFuture.cause();
if (resolveFailureCause != null) {
// Failed to resolve immediately
channel.close();
return channel.newFailedFuture(resolveFailureCause);
}
// Succeeded to resolve immediately; cached? (or did a blocking lookup) // Succeeded to resolve immediately; cached? (or did a blocking lookup)
return doConnect(resolveFuture.getNow(), localAddress, regFuture, channel.newPromise()); return doConnect(resolveFuture.getNow(), localAddress, regFuture, channel.newPromise());
} }