Be a little less eager to retry failed network requests
This is to avoid bogging down the reconciler thread with repeated failing network calls in a short span of time. See https://www.pivotaltracker.com/story/show/143347079
This commit is contained in:
@@ -28,6 +28,7 @@ public class CFCallableContext {
|
||||
|
||||
private final CFParamsProviderMessages paramsProviderMessages;
|
||||
private Exception lastConnectionError;
|
||||
private long lastErrorTime = 0;
|
||||
|
||||
public CFCallableContext(CFParamsProviderMessages paramsProviderMessages) {
|
||||
this.paramsProviderMessages = paramsProviderMessages;
|
||||
@@ -38,6 +39,7 @@ public class CFCallableContext {
|
||||
try {
|
||||
return callable.call();
|
||||
} catch (Exception e) {
|
||||
lastErrorTime = System.currentTimeMillis();
|
||||
throw convertToCfVscodeError(e);
|
||||
}
|
||||
}
|
||||
@@ -61,7 +63,7 @@ public class CFCallableContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasConnectionError() {
|
||||
return this.lastConnectionError != null;
|
||||
public boolean hasExpiredConnectionError() {
|
||||
return this.lastConnectionError != null && System.currentTimeMillis() - lastErrorTime > CFTargetCache.ERROR_EXPIRATION.toMillis();
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,6 @@ public class CFTarget {
|
||||
private LoadingCache<String, List<CFDomain>> domainCache;
|
||||
private LoadingCache<String, List<CFStack>> stacksCache;
|
||||
private CFCallableContext callableContext;
|
||||
|
||||
public CFTarget(String targetName, CFClientParams params, ClientRequests requests,
|
||||
CFCallableContext callableContext) {
|
||||
this.params = params;
|
||||
@@ -111,8 +110,8 @@ public class CFTarget {
|
||||
return callableContext.checkConnection(callable);
|
||||
}
|
||||
|
||||
public boolean hasConnectionError() {
|
||||
return callableContext.hasConnectionError();
|
||||
public boolean hasExpiredConnectionError() {
|
||||
return callableContext.hasExpiredConnectionError();
|
||||
}
|
||||
|
||||
public CFClientParams getParams() {
|
||||
@@ -168,4 +167,5 @@ public class CFTarget {
|
||||
// %o : %s - [%a]
|
||||
return params.getOrgName() + " : " + params.getSpaceName() + " ["+params.getApiUrl()+"]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class CFTargetCache {
|
||||
|
||||
public static final Duration SERVICES_EXPIRATION = Duration.ofSeconds(10);
|
||||
public static final Duration TARGET_EXPIRATION = Duration.ofHours(1);
|
||||
public static final Duration ERROR_EXPIRATION = Duration.ofSeconds(10);
|
||||
|
||||
public CFTargetCache(ClientParamsProvider paramsProvider, CloudFoundryClientFactory clientFactory,
|
||||
ClientTimeouts timeouts) {
|
||||
@@ -75,7 +76,7 @@ public class CFTargetCache {
|
||||
CFTarget target = cache.get(key);
|
||||
if (target != null) {
|
||||
// If any CF errors occurred in the target, refresh once
|
||||
if (target.hasConnectionError()) {
|
||||
if (target.hasExpiredConnectionError()) {
|
||||
cache.refresh(key);
|
||||
target = cache.get(key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user