Skip to content

Commit 4273452

Browse files
committed
Address review comments.
1 parent 6449728 commit 4273452

File tree

2 files changed

+146
-86
lines changed

2 files changed

+146
-86
lines changed

netty/src/main/java/io/grpc/netty/NettyClientTransport.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import io.netty.util.concurrent.GenericFutureListener;
6161
import java.net.SocketAddress;
6262
import java.nio.channels.ClosedChannelException;
63+
import java.util.Collections;
6364
import java.util.LinkedHashMap;
6465
import java.util.Map;
6566
import java.util.concurrent.Executor;
@@ -109,13 +110,17 @@ class NettyClientTransport implements ConnectionClientTransport {
109110
private final boolean useGetForSafeMethods;
110111
private final Ticker ticker;
111112
private final Logger logger = Logger.getLogger(NettyClientTransport.class.getName());
112-
private final LinkedHashMap<String, Status> peerVerificationResults =
113+
private final Map<String, Status> peerVerificationResults = Collections.synchronizedMap(
113114
new LinkedHashMap<String, Status>() {
114115
@Override
115116
protected boolean removeEldestEntry(Map.Entry<String, Status> eldest) {
116117
return size() > 100;
117118
}
118-
};
119+
});
120+
121+
@VisibleForTesting
122+
static boolean enablePerRpcAuthorityCheck =
123+
GrpcUtil.getFlag("GRPC_ENABLE_PER_RPC_AUTHORITY_CHECK", false);
119124

120125
NettyClientTransport(
121126
SocketAddress address,
@@ -209,6 +214,7 @@ public ClientStream newStream(
209214
Status verificationStatus = peerVerificationResults.get(callOptions.getAuthority());
210215
if (verificationStatus == null) {
211216
verificationStatus = negotiator.verifyAuthority(callOptions.getAuthority());
217+
peerVerificationResults.put(callOptions.getAuthority(), verificationStatus);
212218
if (!verificationStatus.isOk()) {
213219
logger.log(Level.WARNING, String.format("Peer hostname verification during rpc failed "
214220
+ "for authority '%s' for method '%s' with the error \"%s\". This will "
@@ -218,7 +224,7 @@ public ClientStream newStream(
218224
}
219225
}
220226
if (!verificationStatus.isOk()) {
221-
if (GrpcUtil.getFlag("GRPC_ENABLE_PER_RPC_AUTHORITY_CHECK", false)) {
227+
if (enablePerRpcAuthorityCheck) {
222228
return new FailingClientStream(verificationStatus, tracers);
223229
}
224230
}

0 commit comments

Comments
 (0)