Skip to content
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

fixes #1166 Handle the LoadBalancingRouterProxyClient has empty host … #1167

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
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 @@ -220,16 +220,21 @@ protected Host selectHost(HttpServerExchange exchange) {
}
String envTag = headers.getFirst(HttpStringConstants.ENV_TAG);
String key = envTag == null ? (serviceUrl != null ? serviceUrl : serviceId) : (serviceUrl != null ? serviceUrl : serviceId) + "|" + envTag;
if(logger.isTraceEnabled()) logger.trace("key = " + key);
AttachmentList<Host> attempted = exchange.getAttachment(ATTEMPTED_HOSTS);
if(logger.isTraceEnabled()) logger.trace("attempted = " + attempted);
Host[] hostArray = this.hosts.get(key);
if(logger.isTraceEnabled()) logger.trace("size = " + hostArray.length + " hostArray = " + hostArray);
if (hostArray == null || hostArray.length == 0) {
// this must be the first this service is called since the router is started. discover here.
if (serviceUrl != null) {
if(logger.isTraceEnabled()) logger.trace("serviceUrl = " + serviceUrl);
try {
URI uri = new URI(serviceUrl);
if (HOST_WHITELIST != null) {
if (HOST_WHITELIST.isHostAllowed(uri)) {
this.hosts.put(key, new Host[] {new Host(serviceId, bindAddress, uri, ssl, options) });
if(logger.isTraceEnabled()) logger.trace("added host to hosts with serviceUrl = " + serviceUrl);
} else {
throw new RuntimeException(String.format("Route to %s is not allowed in the host whitelist", serviceUrl));
}
Expand All @@ -243,11 +248,15 @@ protected Host selectHost(HttpServerExchange exchange) {
throw new RuntimeException(e);
}
} else {
if(logger.isTraceEnabled()) logger.trace("serviceUrl is null, addHosts by serviceId = " + serviceId + " and envTag = " + envTag);
addHosts(serviceId, envTag);
}
hostArray = this.hosts.get(key);
}

if(logger.isTraceEnabled()) logger.trace("hostArray size = " + hostArray.length + " hostArray = " + hostArray);
if(hostArray.length == 0) {
throw new ConfigException(String.format("HostArray is empty. serviceUrl = %s serviceId = %s envTag = %s", serviceUrl, serviceId, envTag));
}
int host = hostSelector.selectHost(hostArray);

final int startHost = host; //if the all hosts have problems we come back to this one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ public List<Map<String, Object>> lookupHealthService(String serviceId, String ta
if (tag != null) {
path = path + "&tag=" + tag;
}
logger.trace("path = {}", path);
if(logger.isTraceEnabled()) logger.trace("path = {}", path);
try {
connection = client.borrowConnection(uri, Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, optionMap).get();
AtomicReference<ClientResponse> reference = send(connection, Methods.GET, path, token, null);
int statusCode = reference.get().getResponseCode();
if (statusCode >= UNUSUAL_STATUS_CODE) {
throw new Exception("Failed to unregister on Consul: " + statusCode);
logger.error("Failed to look up service on Portal with serviceId {} tag {} response code {} and body {}", serviceId, tag, statusCode, reference.get().getAttachment(Http2Client.RESPONSE_BODY));
throw new Exception("Failed to lookup service on Portal: " + statusCode);
} else {
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
services = JsonMapper.string2List(body);
Expand Down