Skip to content

Commit 1ee858f

Browse files
authored
[BUG] Streaming bulk request hangs (#16158)
Signed-off-by: Andriy Redko <[email protected]>
1 parent 0b1650d commit 1ee858f

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5454
- Avoid infinite loop when `flat_object` field contains invalid token ([#15985](https://github.com/opensearch-project/OpenSearch/pull/15985))
5555
- Fix infinite loop in nested agg ([#15931](https://github.com/opensearch-project/OpenSearch/pull/15931))
5656
- Fix race condition in node-join and node-left ([#15521](https://github.com/opensearch-project/OpenSearch/pull/15521))
57+
- Streaming bulk request hangs ([#16158](https://github.com/opensearch-project/OpenSearch/pull/16158))
5758

5859
### Security
5960

plugins/transport-reactor-netty4/src/javaRestTest/java/org/opensearch/rest/ReactorNetty4StreamingIT.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.nio.ByteBuffer;
2222
import java.nio.charset.StandardCharsets;
2323
import java.time.Duration;
24+
import java.util.Locale;
2425
import java.util.stream.IntStream;
2526
import java.util.stream.Stream;
2627

@@ -297,4 +298,31 @@ public void testStreamingBadStream() throws IOException {
297298
assertThat(streamingResponse.getStatusLine().getStatusCode(), equalTo(200));
298299
assertThat(streamingResponse.getWarnings(), empty());
299300
}
301+
302+
public void testStreamingLargeDocument() throws IOException {
303+
final Stream<String> stream = Stream.of(
304+
String.format(
305+
Locale.getDefault(),
306+
"{ \"index\": { \"_index\": \"test-streaming\", \"_id\": \"1\" } }\n{ \"name\": \"%s\" }\n",
307+
randomAlphaOfLength(5000)
308+
)
309+
);
310+
311+
final Duration delay = Duration.ofMillis(1);
312+
final StreamingRequest<ByteBuffer> streamingRequest = new StreamingRequest<>(
313+
"POST",
314+
"/_bulk/stream",
315+
Flux.fromStream(stream).map(s -> ByteBuffer.wrap(s.getBytes(StandardCharsets.UTF_8)))
316+
);
317+
318+
final StreamingResponse<ByteBuffer> streamingResponse = client().streamRequest(streamingRequest);
319+
320+
StepVerifier.create(Flux.from(streamingResponse.getBody()).map(b -> new String(b.array(), StandardCharsets.UTF_8)))
321+
.expectNextMatches(s -> s.contains("\"type\":\"illegal_argument_exception\""))
322+
.expectComplete()
323+
.verify();
324+
325+
assertThat(streamingResponse.getStatusLine().getStatusCode(), equalTo(200));
326+
assertThat(streamingResponse.getWarnings(), empty());
327+
}
300328
}

server/src/main/java/org/opensearch/rest/RestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ public void sendResponse(RestResponse response) {
709709
prepareResponse(response.status(), Map.of("Content-Type", List.of(response.contentType())));
710710
}
711711

712-
Mono.ignoreElements(this).then(Mono.just(response)).subscribe(delegate::sendResponse);
712+
Mono.from(this).ignoreElement().then(Mono.just(response)).subscribe(delegate::sendResponse);
713713
}
714714

715715
@Override

0 commit comments

Comments
 (0)