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

Have circuit breaker succeed on unknown mem usage #33125

Merged

Conversation

danielmitterdorfer
Copy link
Member

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 #31767

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
@danielmitterdorfer danielmitterdorfer added >enhancement review :Core/Infra/Circuit Breakers Track estimates of memory consumption to prevent overload v7.0.0 labels Aug 24, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a suggestion.

return MEMORY_MX_BEAN.getHeapMemoryUsage().getUsed();
try {
return MEMORY_MX_BEAN.getHeapMemoryUsage().getUsed();
} catch (IllegalArgumentException ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither of the methods here document that they can throw an IllegalArgumentException. So this catch looks quite odd and now I wonder if it's too broad. Catching it is fine, but can also check the exception message and assert that it is what we expect it to be? I don't want us to end up suppressing anything else here.

Copy link
Member Author

@danielmitterdorfer danielmitterdorfer Aug 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IllegalArgumentException is thrown by the constructor of MemoryUsage. It does contain a few more precondition checks but I can add an assert. However, for this we need to resort to pattern matching as the message contains absolute numbers, e.g:

committed = 542113792 should be < max = 536870912

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand where it's coming from. I am saying the Javadocs for MemoryMXBean#getHeapMemoryUsage do not relay this fact. That it's coming from a constructor is an implementation detail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. Then I just misunderstood. Anyway, I can implement the assertion as suggested.

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Circuit Breakers Track estimates of memory consumption to prevent overload >enhancement v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants