netty: fix local socket bind

This commit is contained in:
Carl Mastrangelo 2018-10-17 18:34:03 -07:00 committed by GitHub
parent 7675ce2d47
commit 52d6a6e680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -220,11 +220,6 @@ class NettyClientTransport implements ConnectionClientTransport {
// so it is safe to pass the key-value pair to b.option().
b.option((ChannelOption<Object>) entry.getKey(), entry.getValue());
}
SocketAddress localAddress =
localSocketPicker.createSocketAddress(remoteAddress, eagAttributes);
if (localAddress != null) {
b.localAddress(localAddress);
}
/**
* We don't use a ChannelInitializer in the client bootstrap because its "initChannel" method
@ -273,7 +268,13 @@ class NettyClientTransport implements ConnectionClientTransport {
}
});
// Start the connection operation to the server.
channel.connect(remoteAddress);
SocketAddress localAddress =
localSocketPicker.createSocketAddress(remoteAddress, eagAttributes);
if (localAddress != null) {
channel.connect(remoteAddress, localAddress);
} else {
channel.connect(remoteAddress);
}
if (keepAliveManager != null) {
keepAliveManager.onTransportStarted();