Skip to content

Commit

Permalink
check whether the downcast from iter to gnIter succeeded. (#5291) (#5298
Browse files Browse the repository at this point in the history
)

Co-authored-by: Cheng Xuntao <[email protected]>
  • Loading branch information
Sophie-Xie and xtcyclist authored Feb 1, 2023
1 parent c48cbd1 commit 5617371
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/graph/executor/algo/SubgraphExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,20 @@ folly::Future<Status> SubgraphExecutor::handleResponse(RpcResponse&& resps) {

void SubgraphExecutor::filterEdges(int version) {
auto iter = ectx_->getVersionedResult(subgraph_->outputVar(), version).iter();
auto* gnIter = static_cast<GetNeighborsIter*>(iter.get());
while (gnIter->valid()) {
const auto& dst = gnIter->getEdgeProp("*", nebula::kDst);
if (validVids_.find(dst) == validVids_.end()) {
auto edge = gnIter->getEdge();
gnIter->erase();
} else {
gnIter->next();
auto* iterPtr = iter.get();
if (iterPtr->isGetNeighborsIter()) {
auto* gnIter = static_cast<GetNeighborsIter*>(iterPtr);
while (gnIter->valid()) {
const auto& dst = gnIter->getEdgeProp("*", nebula::kDst);
if (validVids_.find(dst) == validVids_.end()) {
auto edge = gnIter->getEdge();
gnIter->erase();
} else {
gnIter->next();
}
}
gnIter->reset();
}
gnIter->reset();
ResultBuilder builder;
builder.iter(std::move(iter));
ectx_->setVersionedResult(subgraph_->outputVar(), builder.build(), version);
Expand Down
3 changes: 3 additions & 0 deletions src/graph/executor/query/DataCollectExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Status DataCollectExecutor::collectSubgraph(const std::vector<std::string>& vars
ds.colNames = std::move(colNames_);
const auto& hist = ectx_->getHistory(vars[0]);
for (const auto& result : hist) {
if (!result.iterRef()->isGetNeighborsIter()) {
continue;
}
auto iter = result.iter();
auto* gnIter = static_cast<GetNeighborsIter*>(iter.get());
List vertices;
Expand Down
23 changes: 23 additions & 0 deletions tests/tck/features/bugfix/FixIterCrash.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2022 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
Feature: FixIterCrash

Scenario: Fix GetNeighborsIter Crash
Given an empty graph
And having executed:
"""
CREATE SPACE nba_FixIterCrash as nba
"""
And wait 6 seconds
And having executed:
"""
USE nba_FixIterCrash
"""
When executing query:
"""
GO from 'Tim Duncan' OVER serve YIELD serve._src AS id |
GET SUBGRAPH WITH PROP FROM $-.id
YIELD vertices as nodes, edges as relationships
"""
Then the execution should be successful

0 comments on commit 5617371

Please sign in to comment.