我正在经历一些奇怪的行为,我无法解释。对于我的用例,我使用等待性和httpRequests来检查服务是否已经部署。如果服务尚未准备就绪,OpenShift将返回503,否则返回200。在2个请求(接收到503)之后,正常行为变为超时。大约2分钟后,手动请求仍会收到503和200。
22-05-2020 11:56:33.448 INFO RetryingHttpClient.send [32]-发送请求:GEThttps://serviceurlHTTP / 1.1
22-05-2020 11:56:33.646 INFO RetryingHttpClient.send [34]-接收503
22-05-2020 11:56:43.987 INFO RetryingHttpClient.send [32]-发送请求:GEThttps://serviceurlHTTP / 1.1
22-05-2020 11:56:43.992 INFO RetryingHttpClient.send [34]-接收503
22-05-2020 11:56:54.071 INFO RetryingHttpClient.send [32]-发送请求:GEThttps://serviceurlHTTP / 1.1
->超时
public void send(HttpUriRequest request) {
log.info("Sending request (retry for 10m): {}", request);
await().atMost(10, TimeUnit.MINUTES)
.pollInterval(5, TimeUnit.SECONDS)
.ignoreExceptions()
.until(() -> client.execute(request), ResponseChecker::is2xxOrRedirectResponse);
}
为了消除某些潜在原因,我使用简单的for循环,睡眠和扩展日志记录重写了逻辑,并使用了一些可从任何地方访问的外部url。
public void send(HttpUriRequest request) {
for(int i=1;60>=i;i++){
try {
log.info("Sending request: {}", request);
HttpResponse res = client.execute(request);
log.info("Receiving {}", res.getStatusLine().getStatusCode());
try{
Thread.sleep(10000);
}catch(InterruptedException edf){
System.out.println("Thread was interrupted!");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
22-05-2020 14:56:33.448 INFO RetryingHttpClient.send [32]-发送请求:GEThttps://www.google.deHTTP / 1.1
22-05-2020 14:56:33.686 INFO RetryingHttpClient.send [34]-接收200
22-05-2020 14:56:43.687 INFO RetryingHttpClient.send [32]-发送请求:GEThttps://www.google.deHTTP / 1.1
22-05-2020 14:56:43.770 INFO RetryingHttpClient.send [34]-接收200
22-05-2020 14:56:53.771 INFO RetryingHttpClient.send [32]-发送请求:GEThttps://www.google.deHTTP / 1.1
->超时
[如果您有任何想法,可能的潜在原因是我会很高兴。谢谢。
您的代码正在泄漏连接。密切回应。