From 7313ad5b29059eb381efd20a6c77c472f527d71c Mon Sep 17 00:00:00 2001 From: David Roberts Date: Thu, 17 Aug 2017 14:54:31 +0100 Subject: [PATCH] Make AllocatedPersistentTask members volatile (#2297) These members are default initialized on contruction and then set by the init() method. It's possible that another thread accessing the object after init() is called could still see the null/0 values, depending on how the compiler optimizes the code. --- .../persistent/AllocatedPersistentTask.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/persistent/AllocatedPersistentTask.java b/server/src/main/java/org/elasticsearch/persistent/AllocatedPersistentTask.java index 131d7727ce0..21d3fa7e957 100644 --- a/server/src/main/java/org/elasticsearch/persistent/AllocatedPersistentTask.java +++ b/server/src/main/java/org/elasticsearch/persistent/AllocatedPersistentTask.java @@ -36,16 +36,16 @@ import java.util.concurrent.atomic.AtomicReference; * Represents a executor node operation that corresponds to a persistent task */ public class AllocatedPersistentTask extends CancellableTask { - private String persistentTaskId; - private long allocationId; + private volatile String persistentTaskId; + private volatile long allocationId; private final AtomicReference state; @Nullable - private Exception failure; + private volatile Exception failure; - private PersistentTasksService persistentTasksService; - private Logger logger; - private TaskManager taskManager; + private volatile PersistentTasksService persistentTasksService; + private volatile Logger logger; + private volatile TaskManager taskManager; public AllocatedPersistentTask(long id, String type, String action, String description, TaskId parentTask) {