diff --git a/netty/src/main/java/io/grpc/netty/NettyClientTransport.java b/netty/src/main/java/io/grpc/netty/NettyClientTransport.java index 72eb5f61d2..b23acbbcae 100644 --- a/netty/src/main/java/io/grpc/netty/NettyClientTransport.java +++ b/netty/src/main/java/io/grpc/netty/NettyClientTransport.java @@ -220,11 +220,6 @@ class NettyClientTransport implements ConnectionClientTransport { // so it is safe to pass the key-value pair to b.option(). b.option((ChannelOption) 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();