From d7f1a2a97cb84dd11f2cbc3ba27c9a5c425ee927 Mon Sep 17 00:00:00 2001 From: skyan Date: Sun, 9 Nov 2025 16:20:57 +0800 Subject: [PATCH] Fix graph not detecting errors when GraphExecutor::run fails * 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 --- .gitignore | 10 +++++++++- src/babylon/anyflow/executor.cpp | 6 ++---- src/babylon/anyflow/vertex.cpp | 9 +++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index f77ad954..f97b95e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,10 @@ .idea/ -cmake-build-* \ No newline at end of file +cmake-build-* +bazel-bin +bazel-genfiles +bazel-out +bazel-testlogs +bazel-workspace +bazel-babylon +MODULE.bazel +MODULE.bazel.lock \ No newline at end of file diff --git a/src/babylon/anyflow/executor.cpp b/src/babylon/anyflow/executor.cpp index b560b339..42ab3db9 100644 --- a/src/babylon/anyflow/executor.cpp +++ b/src/babylon/anyflow/executor.cpp @@ -52,18 +52,16 @@ Closure ThreadPoolGraphExecutor::create_closure() noexcept { int ThreadPoolGraphExecutor::run(GraphVertex* vertex, GraphVertexClosure&& closure) noexcept { - _executor.submit([captured_closure = ::std::move(closure), vertex]() mutable { + return _executor.submit([captured_closure = ::std::move(closure), vertex]() mutable { vertex->run(::std::move(captured_closure)); }); - return 0; } int ThreadPoolGraphExecutor::run(ClosureContext* closure, Closure::Callback* callback) noexcept { - _executor.submit([=] { + return _executor.submit([=] { closure->run(callback); }); - return 0; } } // namespace anyflow diff --git a/src/babylon/anyflow/vertex.cpp b/src/babylon/anyflow/vertex.cpp index a892b3ec..0ca9c5a0 100644 --- a/src/babylon/anyflow/vertex.cpp +++ b/src/babylon/anyflow/vertex.cpp @@ -230,8 +230,13 @@ void GraphVertex::invoke(VertexStack& runnable_vertexes) noexcept { _runnable_vertexes = &runnable_vertexes; run(GraphVertexClosure(*_closure, *this)); } else { - _builder->graph().executor().run(this, - GraphVertexClosure(*_closure, *this)); + GraphVertexClosure closure(*_closure, *this); + if (ABSL_PREDICT_FALSE(0 != _builder->graph().executor().run(this, + ::std::move(closure)))) { + // executor.run 返回失败时,closure 可能已被 move,需要重新创建来标记错误 + GraphVertexClosure error_closure(*_closure, *this); + error_closure.done(-1); + } } } else { // 不允许平凡模式情况下,不设置_runnable_vertexes