Skip to content

Commit 512585d

Browse files
committed
Fix race condition in adding TimeoutClusterStateListener
Fixes elastic#2658
1 parent 435eabd commit 512585d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,19 @@ public void remove(LocalNodeMasterListener listener) {
189189
localNodeMasterListeners.remove(listener);
190190
}
191191

192-
public void add(TimeValue timeout, final TimeoutClusterStateListener listener) {
192+
public void add(final TimeValue timeout, final TimeoutClusterStateListener listener) {
193193
if (lifecycle.stoppedOrClosed()) {
194194
listener.onClose();
195195
return;
196196
}
197-
NotifyTimeout notifyTimeout = new NotifyTimeout(listener, timeout);
198-
notifyTimeout.future = threadPool.schedule(timeout, ThreadPool.Names.GENERIC, notifyTimeout);
199-
onGoingTimeouts.add(notifyTimeout);
200-
clusterStateListeners.add(listener);
201197
// call the post added notification on the same event thread
202198
updateTasksExecutor.execute(new Runnable() {
203199
@Override
204200
public void run() {
201+
NotifyTimeout notifyTimeout = new NotifyTimeout(listener, timeout);
202+
notifyTimeout.future = threadPool.schedule(timeout, ThreadPool.Names.GENERIC, notifyTimeout);
203+
onGoingTimeouts.add(notifyTimeout);
204+
clusterStateListeners.add(listener);
205205
listener.postAdded();
206206
}
207207
});

0 commit comments

Comments
 (0)