mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Properly remove security index recovered state consumer (#112927)
One of the security index state change listeners attempts to remove itself once it has received the expected event. However, since the consumer is a lambda, `this` in `stateChangeListeners.remove(this);` actually refers to the enclosing class instance (`SecurityIndexManager.this`) which results in a noop and not an actual removal of the relevant consumer. This PR fixes this by converting the lambda to an anonymous class. It's technically a bug, but so minor that it doesn't warrant a bug changelog IMO; so I'm labelling it a non-issue instead.
This commit is contained in:
parent
ef154612b7
commit
cfe8dfa322
1 changed files with 10 additions and 7 deletions
|
@ -344,13 +344,16 @@ public class SecurityIndexManager implements ClusterStateListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStateRecovered(Consumer<State> recoveredStateConsumer) {
|
public void onStateRecovered(Consumer<State> recoveredStateConsumer) {
|
||||||
BiConsumer<State, State> stateChangeListener = (previousState, nextState) -> {
|
BiConsumer<State, State> stateChangeListener = new BiConsumer<>() {
|
||||||
boolean stateJustRecovered = previousState == UNRECOVERED_STATE && nextState != UNRECOVERED_STATE;
|
@Override
|
||||||
boolean stateAlreadyRecovered = previousState != UNRECOVERED_STATE;
|
public void accept(State previousState, State nextState) {
|
||||||
if (stateJustRecovered) {
|
boolean stateJustRecovered = previousState == UNRECOVERED_STATE && nextState != UNRECOVERED_STATE;
|
||||||
recoveredStateConsumer.accept(nextState);
|
boolean stateAlreadyRecovered = previousState != UNRECOVERED_STATE;
|
||||||
} else if (stateAlreadyRecovered) {
|
if (stateJustRecovered) {
|
||||||
stateChangeListeners.remove(this);
|
recoveredStateConsumer.accept(nextState);
|
||||||
|
} else if (stateAlreadyRecovered) {
|
||||||
|
stateChangeListeners.remove(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
stateChangeListeners.add(stateChangeListener);
|
stateChangeListeners.add(stateChangeListener);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue