Skip to content

Commit c230b4f

Browse files
authored
Fix graph not detecting errors when GraphExecutor::run fails (baidu#110)
* In extreme cases such as when the thread pool is full, GraphExecutor::run may return an error. Previously, the graph did not detect these errors, which could cause other nodes to not execute without reporting any error. * Also update .gitignore to exclude bazel build artifacts and module files
1 parent 628270a commit c230b4f

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
.idea/
2-
cmake-build-*
2+
cmake-build-*
3+
bazel-bin
4+
bazel-genfiles
5+
bazel-out
6+
bazel-testlogs
7+
bazel-workspace
8+
bazel-babylon
9+
MODULE.bazel
10+
MODULE.bazel.lock

src/babylon/anyflow/executor.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,16 @@ Closure ThreadPoolGraphExecutor::create_closure() noexcept {
5252

5353
int ThreadPoolGraphExecutor::run(GraphVertex* vertex,
5454
GraphVertexClosure&& closure) noexcept {
55-
_executor.submit([captured_closure = ::std::move(closure), vertex]() mutable {
55+
return _executor.submit([captured_closure = ::std::move(closure), vertex]() mutable {
5656
vertex->run(::std::move(captured_closure));
5757
});
58-
return 0;
5958
}
6059

6160
int ThreadPoolGraphExecutor::run(ClosureContext* closure,
6261
Closure::Callback* callback) noexcept {
63-
_executor.submit([=] {
62+
return _executor.submit([=] {
6463
closure->run(callback);
6564
});
66-
return 0;
6765
}
6866

6967
} // namespace anyflow

src/babylon/anyflow/vertex.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,13 @@ void GraphVertex::invoke(VertexStack& runnable_vertexes) noexcept {
230230
_runnable_vertexes = &runnable_vertexes;
231231
run(GraphVertexClosure(*_closure, *this));
232232
} else {
233-
_builder->graph().executor().run(this,
234-
GraphVertexClosure(*_closure, *this));
233+
GraphVertexClosure closure(*_closure, *this);
234+
if (ABSL_PREDICT_FALSE(0 != _builder->graph().executor().run(this,
235+
::std::move(closure)))) {
236+
// executor.run 返回失败时,closure 可能已被 move,需要重新创建来标记错误
237+
GraphVertexClosure error_closure(*_closure, *this);
238+
error_closure.done(-1);
239+
}
235240
}
236241
} else {
237242
// 不允许平凡模式情况下,不设置_runnable_vertexes

0 commit comments

Comments
 (0)