elastic/elasticsearch

Transport request handlers should be registered safely

Open

#53.178 aperta il 5 mar 2020

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Java (25.882 fork)batch import
:Core/Infra/Core>refactoringTeam:Core/Infrahelp wanted

Metriche repository

Star
 (76.700 star)
Metriche merge PR
 (Merge medio 2g) (1000 PR mergiate in 30 g)

Descrizione

Similar to #38560 and #51622, the HandledTransportAction registers a non-static inner class with the transport service as the handler for the requests of a given action as seen below.

https://github.com/elastic/elasticsearch/blob/898012028e5cd9c6d6058d2063d772fabdea305c/server/src/main/java/org/elasticsearch/action/support/HandledTransportAction.java#L52-L66

In the other issues, a reference to the instance being constructed, this, was explicitly passed to another service. In this case, the reference is implicit since the inner class TransportHandler is not static and has a reference to the outer class. Since the inner class is published and calls methods within the outer class, there is a chance that this could happen before the outer class is fully constructed, which violates the JLS.

For correctness, this code should be changed so that the handler registration no longer occurs within a constructor. However, given the use of guice to construct transport actions and eventual refactoring to remove guice it may be best to consider this as part of that effort.

Guida contributor