[ML] Close sample stream in post_data endpoint (#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.
This commit is contained in:
David Roberts 2019-06-14 17:53:55 +01:00
parent a7bdea8a15
commit 3928c624a3
1 changed files with 3 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessManage
import org.elasticsearch.xpack.ml.job.process.autodetect.params.DataLoadParams;
import org.elasticsearch.xpack.ml.job.process.autodetect.params.TimeRange;
import java.io.InputStream;
import java.util.Optional;
public class TransportPostDataAction extends TransportJobTaskAction<PostDataAction.Request, PostDataAction.Response> {
@ -37,8 +38,8 @@ public class TransportPostDataAction extends TransportJobTaskAction<PostDataActi
ActionListener<PostDataAction.Response> listener) {
TimeRange timeRange = TimeRange.builder().startTime(request.getResetStart()).endTime(request.getResetEnd()).build();
DataLoadParams params = new DataLoadParams(timeRange, Optional.ofNullable(request.getDataDescription()));
try {
processManager.processData(task, analysisRegistry, request.getContent().streamInput(), request.getXContentType(),
try (InputStream contentStream = request.getContent().streamInput()) {
processManager.processData(task, analysisRegistry, contentStream, request.getXContentType(),
params, (dataCounts, e) -> {
if (dataCounts != null) {
listener.onResponse(new PostDataAction.Response(dataCounts));