Skip to content

Commit 122e95e

Browse files
drempapiselasticsearchmachine
andauthored
[9.1] close properly byte stream on failure: (elastic#137810) (elastic#137869)
* update * Fix resource closing in SearchQueryThenFetchAsyncAction * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 3566b7a commit 122e95e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

server/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,18 +843,26 @@ void onShardDone() {
843843
var channelListener = new ChannelActionListener<>(channel);
844844
RecyclerBytesStreamOutput out = dependencies.transportService.newNetworkBytesStream();
845845
out.setTransportVersion(channel.getVersion());
846+
847+
boolean success = false;
846848
try (queryPhaseResultConsumer) {
847849
Exception reductionFailure = queryPhaseResultConsumer.failure.get();
848850
if (reductionFailure == null) {
849851
writeSuccessfulResponse(out);
850852
} else {
851853
writeReductionFailureResponse(out, reductionFailure);
852854
}
855+
success = true;
853856
} catch (IOException e) {
854857
releaseAllResultsContexts();
855858
channelListener.onFailure(e);
856859
return;
860+
} finally {
861+
if (success == false) {
862+
out.close();
863+
}
857864
}
865+
858866
ActionListener.respondAndRelease(channelListener, new BytesTransportResponse(out.moveToBytesReference()));
859867
}
860868

0 commit comments

Comments
 (0)