Skip to content

Commit

Permalink
Have circuit breaker succeed on unknown mem usage
Browse files Browse the repository at this point in the history
With this commit we implement a workaround for
https://bugs.openjdk.java.net/browse/JDK-8207200 which is a race
condition in the JVM that results in `IllegalArgumentException` to be
thrown in rare cases when we determine memory usage via `MemoryMXBean`.
As we do not want to fail requests in those cases we always return zero
memory usage.

Relates elastic#31767
  • Loading branch information
danielmitterdorfer committed Aug 24, 2018
1 parent a211d24 commit 22c4531
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,15 @@ private ParentMemoryUsage parentUsed(long newBytesReserved) {

//package private to allow overriding it in tests
long currentMemoryUsage() {
return MEMORY_MX_BEAN.getHeapMemoryUsage().getUsed();
try {
return MEMORY_MX_BEAN.getHeapMemoryUsage().getUsed();
} catch (IllegalArgumentException ex) {
// This exception can happen (rarely) due to a race condition in the JVM when determining usage of memory pools. We do not want
// to fail requests because of this and thus return zero memory usage in this case. While we could also return the most
// recently determined memory usage, we would overestimate memory usage immediately after a garbage collection event.
logger.info("Cannot determine current memory usage due to JDK-8207200.", ex);
return 0;
}
}

/**
Expand Down

0 comments on commit 22c4531

Please sign in to comment.