Skip to content

Commit 8db55ea

Browse files
authored
[ML] Close sample stream in post_data endpoint (elastic#43235)
A static code analysis revealed that we are not closing the input stream in the post_data endpoint. This actually makes no difference in practice, as the particular InputStream implementation in this case is org.elasticsearch.common.bytes.BytesReferenceStreamInput and its close() method is a no-op. However, it is good practice to close the stream anyway.
1 parent 6e60945 commit 8db55ea

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPostDataAction.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.xpack.ml.job.process.autodetect.params.DataLoadParams;
1818
import org.elasticsearch.xpack.ml.job.process.autodetect.params.TimeRange;
1919

20+
import java.io.InputStream;
2021
import java.util.Optional;
2122

2223
public class TransportPostDataAction extends TransportJobTaskAction<PostDataAction.Request, PostDataAction.Response> {
@@ -37,8 +38,8 @@ protected void taskOperation(PostDataAction.Request request, TransportOpenJobAct
3738
ActionListener<PostDataAction.Response> listener) {
3839
TimeRange timeRange = TimeRange.builder().startTime(request.getResetStart()).endTime(request.getResetEnd()).build();
3940
DataLoadParams params = new DataLoadParams(timeRange, Optional.ofNullable(request.getDataDescription()));
40-
try {
41-
processManager.processData(task, analysisRegistry, request.getContent().streamInput(), request.getXContentType(),
41+
try (InputStream contentStream = request.getContent().streamInput()) {
42+
processManager.processData(task, analysisRegistry, contentStream, request.getXContentType(),
4243
params, (dataCounts, e) -> {
4344
if (dataCounts != null) {
4445
listener.onResponse(new PostDataAction.Response(dataCounts));

0 commit comments

Comments
 (0)