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

HashMap is is not thread safe. Field fileDetails is synchronized in 20 locations, but not in 1 (the 21st) location #43840

Closed
paulward24 opened this issue Jul 1, 2019 · 1 comment
Labels
>bug :Distributed/Recovery Anything around constructing a new shard, either from a local or a remote source.

Comments

@paulward24
Copy link
Contributor

I submitted a CR for this issue:

#43839

The field fileDetails (a HashMap, i.e., not thread safe)

https:/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java#L679

is used only in synchronzied methods (in about 20 locations), e.g.,:

https:/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java#L767-L768

i.e., including .size().

This is correct, because according to JDK:

If multiple threads access a hash map concurrently, and at least
one of the threads modifies the map structurally, it must be
synchronized externally.

https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html

However, in the 21st location, here:

https:/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java#L958

the method is not synchronized.

This CR simply adds the keyword synchronized to the method, just like for all the other places.

@dnhatn dnhatn added the :Distributed/Recovery Anything around constructing a new shard, either from a local or a remote source. label Jul 1, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Distributed/Recovery Anything around constructing a new shard, either from a local or a remote source.
Projects
None yet
Development

No branches or pull requests

3 participants