elastic/elasticsearch

Transport request handlers should be registered safely

Open

#53,178 opened on Mar 5, 2020

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Java (76,700 stars) (25,882 forks)batch import
:Core/Infra/Core>refactoringTeam:Core/Infrahelp wanted

Description

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.

Contributor guide