|
27 | 27 | import org.elasticsearch.common.util.Maps;
|
28 | 28 | import org.elasticsearch.common.util.concurrent.AtomicArray;
|
29 | 29 | import org.elasticsearch.core.Releasable;
|
30 |
| -import org.elasticsearch.core.Releasables; |
31 | 30 | import org.elasticsearch.index.shard.ShardId;
|
32 | 31 | import org.elasticsearch.search.SearchContextMissingException;
|
33 | 32 | import org.elasticsearch.search.SearchPhaseResult;
|
@@ -102,7 +101,7 @@ abstract class AbstractSearchAsyncAction<Result extends SearchPhaseResult> exten
|
102 | 101 | private final AtomicBoolean requestCancelled = new AtomicBoolean();
|
103 | 102 |
|
104 | 103 | // protected for tests
|
105 |
| - protected final List<Releasable> releasables = new ArrayList<>(); |
| 104 | + protected final SubscribableListener<Void> doneFuture = new SubscribableListener<>(); |
106 | 105 |
|
107 | 106 | AbstractSearchAsyncAction(
|
108 | 107 | String name,
|
@@ -151,7 +150,7 @@ abstract class AbstractSearchAsyncAction<Result extends SearchPhaseResult> exten
|
151 | 150 | this.executor = executor;
|
152 | 151 | this.request = request;
|
153 | 152 | this.task = task;
|
154 |
| - this.listener = ActionListener.runAfter(listener, () -> Releasables.close(releasables)); |
| 153 | + this.listener = ActionListener.runBefore(listener, () -> doneFuture.onResponse(null)); |
155 | 154 | this.nodeIdToConnection = nodeIdToConnection;
|
156 | 155 | this.concreteIndexBoosts = concreteIndexBoosts;
|
157 | 156 | this.clusterStateVersion = clusterState.version();
|
@@ -182,7 +181,12 @@ protected void notifyListShards(
|
182 | 181 | * Registers a {@link Releasable} that will be closed when the search request finishes or fails.
|
183 | 182 | */
|
184 | 183 | public void addReleasable(Releasable releasable) {
|
185 |
| - releasables.add(releasable); |
| 184 | + var doneFuture = this.doneFuture; |
| 185 | + if (doneFuture.isDone()) { |
| 186 | + releasable.close(); |
| 187 | + } else { |
| 188 | + doneFuture.addListener(ActionListener.releasing((releasable))); |
| 189 | + } |
186 | 190 | }
|
187 | 191 |
|
188 | 192 | /**
|
|
0 commit comments