Skip to content

Commit

Permalink
Fix double-checked locking in ConnectionFactory (#11014)
Browse files Browse the repository at this point in the history
The `_defaultTransport` in `ConnectionFactory` is created using
double-checked locking.

https://github.com/apache/pinot/blob/03b9d4a708e6d09838e902857ebe1f255ced4ba1/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/ConnectionFactory.java#L211-L222

However, the current implementation is buggy as described in
https://rules.sonarsource.com/java/RSPEC-2168/. To fix it, make the field
`volatile`.
  • Loading branch information
lucifer4j authored Jul 8, 2023
1 parent 1b81eba commit 457c2b7
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Creates connections to Pinot, given various initialization methods.
*/
public class ConnectionFactory {
private static PinotClientTransport _defaultTransport;
private static volatile PinotClientTransport _defaultTransport;

private ConnectionFactory() {
}
Expand Down

0 comments on commit 457c2b7

Please sign in to comment.