Skip to content

Commit

Permalink
fix(hystrix): prevent silent NPE after timeout (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeach authored May 24, 2018
1 parent c480983 commit f5ddbc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public List<Account> getAccounts() {
return accountCache.get();
},
(Throwable cause) -> {
log.warn("Falling back to account cache. Cause: " + cause.getMessage());
logFallback("account", cause);
List<Account> accounts = accountCache.get();
if (accounts == null) {
throw new HystrixBadRequestException("Clouddriver is unavailable", cause);
Expand All @@ -91,7 +91,7 @@ public List<Application> getApplications() {
return applicationCache.get();
},
(Throwable cause) -> {
log.warn("Falling back to application cache. Cause: " + cause.getMessage());
logFallback("application", cause);
List<Application> applications = applicationCache.get();
if (applications == null) {
throw new HystrixBadRequestException("Clouddriver is unavailable", cause);
Expand All @@ -100,4 +100,9 @@ public List<Application> getApplications() {
})
.execute();
}

private static void logFallback(String resource, Throwable cause) {
String message = cause != null ? "Cause: " + cause.getMessage() : "";
log.info("Falling back to {} cache. {}", resource, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public List<Application> getAllApplicationPermissions() {
return applicationCache.get();
},
(Throwable cause) -> {
log.warn("Falling back to application cache. Cause: " + cause.getMessage());
logFallback("application", cause);
List<Application> applications = applicationCache.get();
if (applications == null) {
throw new HystrixBadRequestException("Front50 is unavailable", cause);
Expand All @@ -87,12 +87,17 @@ public List<ServiceAccount> getAllServiceAccounts() {
return serviceAccountCache.get();
},
(Throwable cause) -> {
log.warn("Falling back to service account cache. Cause: " + cause.getMessage());
logFallback("service account", cause);
List<ServiceAccount> serviceAccounts = serviceAccountCache.get();
if (serviceAccounts == null) {
throw new HystrixBadRequestException("Front50 is unavailable", cause);
}
return serviceAccounts;
}).execute();
}

private static void logFallback(String resource, Throwable cause) {
String message = cause != null ? "Cause: " + cause.getMessage() : "";
log.info("Falling back to {} cache. {}", resource, message);
}
}

0 comments on commit f5ddbc2

Please sign in to comment.