Skip to content

Commit 8374b1c

Browse files
Change the stream parsing loop (#1449)
Fix the case when the stream is closed before the parsing is started. Resolves: OLPEDGE-2851 Signed-off-by: Mykhailo Kuchma <ext-mykhailo.kuchma@here.com>
1 parent 68ff507 commit 8374b1c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

olp-cpp-sdk-dataservice-read/src/repositories/PartitionsRepository.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ client::ApiNoResponse PartitionsRepository::ParsePartitionsStream(
632632
client::CancellationContext context) {
633633
rapidjson::ParseResult parse_result;
634634

635-
// Retry to parse the stream until it's closed.
636-
while (!async_stream->IsClosed()) {
635+
// We must perform at least one attempt to parse.
636+
do {
637637
rapidjson::Reader reader;
638638
auto partitions_handler =
639639
std::make_shared<repository::PartitionsSaxHandler>(partition_callback);
@@ -650,15 +650,18 @@ client::ApiNoResponse PartitionsRepository::ParsePartitionsStream(
650650

651651
parse_result = reader.Parse<rapidjson::kParseIterativeFlag>(
652652
*json_stream, *partitions_handler);
653-
}
654-
655-
if (!parse_result) {
656-
return client::ApiError(parse_result.Code(), "Parsing error");
657-
}
653+
// Retry to parse the stream until it's closed.
654+
} while (!async_stream->IsClosed());
658655

659656
auto error = async_stream->GetError();
660657

661-
return error ? client::ApiNoResponse(*error) : client::ApiNoResult{};
658+
if (error) {
659+
return client::ApiNoResponse(*error);
660+
} else if (!parse_result) {
661+
return client::ApiError(parse_result.Code(), "Parsing error");
662+
} else {
663+
return client::ApiNoResult{};
664+
}
662665
}
663666

664667
void PartitionsRepository::StreamPartitions(

0 commit comments

Comments
 (0)