From bb19cc135df4a29df52ffc0cfc90f67b388f9ca7 Mon Sep 17 00:00:00 2001 From: yixinglu <2520865+yixinglu@users.noreply.github.com> Date: Thu, 10 Mar 2022 13:52:08 +0800 Subject: [PATCH] Fix lambda capture bug in GraphStorageLocalServer This will crash the daemon --- src/storage/GraphStorageLocalServer.cpp | 59 ++++++++++++++----------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/storage/GraphStorageLocalServer.cpp b/src/storage/GraphStorageLocalServer.cpp index 34046ce69ca..697af47f436 100644 --- a/src/storage/GraphStorageLocalServer.cpp +++ b/src/storage/GraphStorageLocalServer.cpp @@ -5,18 +5,23 @@ #include "GraphStorageLocalServer.h" +#include #include #include "common/base/Base.h" #include "storage/GraphStorageServiceHandler.h" -#define LOCAL_RETURN_FUTURE(threadManager, respType, callFunc) \ - auto promise = std::make_shared>(); \ - auto f = promise->getFuture(); \ - threadManager->add([&, promise] { \ - std::dynamic_pointer_cast(handler_)->callFunc(request).thenValue( \ - [promise](respType&& resp) { promise->setValue(std::move(resp)); }); \ - }); \ +using folly::exception_wrapper; + +#define LOCAL_RETURN_FUTURE(RespType, callFunc) \ + auto promise = std::make_shared>(); \ + auto f = promise->getFuture(); \ + threadManager_->add([this, promise, request] { \ + std::dynamic_pointer_cast(handler_) \ + ->callFunc(std::move(request)) \ + .thenValue([promise](RespType&& resp) { promise->setValue(std::move(resp)); }) \ + .thenError([promise](exception_wrapper&& ex) { promise->setException(std::move(ex)); }); \ + }); \ return f; namespace nebula::storage { @@ -55,102 +60,102 @@ void GraphStorageLocalServer::stop() { folly::Future GraphStorageLocalServer::future_getNeighbors( const cpp2::GetNeighborsRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::GetNeighborsResponse, future_getNeighbors); + LOCAL_RETURN_FUTURE(cpp2::GetNeighborsResponse, future_getNeighbors); } folly::Future GraphStorageLocalServer::future_addVertices( const cpp2::AddVerticesRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ExecResponse, future_addVertices); + LOCAL_RETURN_FUTURE(cpp2::ExecResponse, future_addVertices); } folly::Future GraphStorageLocalServer::future_chainAddEdges( const cpp2::AddEdgesRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ExecResponse, future_chainAddEdges); + LOCAL_RETURN_FUTURE(cpp2::ExecResponse, future_chainAddEdges); } folly::Future GraphStorageLocalServer::future_addEdges( const cpp2::AddEdgesRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ExecResponse, future_addEdges); + LOCAL_RETURN_FUTURE(cpp2::ExecResponse, future_addEdges); } folly::Future GraphStorageLocalServer::future_getProps( const cpp2::GetPropRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::GetPropResponse, future_getProps); + LOCAL_RETURN_FUTURE(cpp2::GetPropResponse, future_getProps); } folly::Future GraphStorageLocalServer::future_deleteEdges( const cpp2::DeleteEdgesRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ExecResponse, future_deleteEdges); + LOCAL_RETURN_FUTURE(cpp2::ExecResponse, future_deleteEdges); } folly::Future GraphStorageLocalServer::future_chainDeleteEdges( const cpp2::DeleteEdgesRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ExecResponse, future_chainDeleteEdges); + LOCAL_RETURN_FUTURE(cpp2::ExecResponse, future_chainDeleteEdges); } folly::Future GraphStorageLocalServer::future_deleteVertices( const cpp2::DeleteVerticesRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ExecResponse, future_deleteVertices); + LOCAL_RETURN_FUTURE(cpp2::ExecResponse, future_deleteVertices); } folly::Future GraphStorageLocalServer::future_deleteTags( const cpp2::DeleteTagsRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ExecResponse, future_deleteTags); + LOCAL_RETURN_FUTURE(cpp2::ExecResponse, future_deleteTags); } folly::Future GraphStorageLocalServer::future_updateVertex( const cpp2::UpdateVertexRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::UpdateResponse, future_updateVertex); + LOCAL_RETURN_FUTURE(cpp2::UpdateResponse, future_updateVertex); } folly::Future GraphStorageLocalServer::future_chainUpdateEdge( const cpp2::UpdateEdgeRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::UpdateResponse, future_chainUpdateEdge); + LOCAL_RETURN_FUTURE(cpp2::UpdateResponse, future_chainUpdateEdge); } folly::Future GraphStorageLocalServer::future_updateEdge( const cpp2::UpdateEdgeRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::UpdateResponse, future_updateEdge); + LOCAL_RETURN_FUTURE(cpp2::UpdateResponse, future_updateEdge); } folly::Future GraphStorageLocalServer::future_getUUID( const cpp2::GetUUIDReq& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::GetUUIDResp, future_getUUID); + LOCAL_RETURN_FUTURE(cpp2::GetUUIDResp, future_getUUID); } folly::Future GraphStorageLocalServer::future_lookupIndex( const cpp2::LookupIndexRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::LookupIndexResp, future_lookupIndex); + LOCAL_RETURN_FUTURE(cpp2::LookupIndexResp, future_lookupIndex); } folly::Future GraphStorageLocalServer::future_lookupAndTraverse( const cpp2::LookupAndTraverseRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::GetNeighborsResponse, future_lookupAndTraverse); + LOCAL_RETURN_FUTURE(cpp2::GetNeighborsResponse, future_lookupAndTraverse); } folly::Future GraphStorageLocalServer::future_scanVertex( const cpp2::ScanVertexRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ScanResponse, future_scanVertex); + LOCAL_RETURN_FUTURE(cpp2::ScanResponse, future_scanVertex); } folly::Future GraphStorageLocalServer::future_scanEdge( const cpp2::ScanEdgeRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ScanResponse, future_scanEdge); + LOCAL_RETURN_FUTURE(cpp2::ScanResponse, future_scanEdge); } folly::Future GraphStorageLocalServer::future_get( const cpp2::KVGetRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::KVGetResponse, future_get); + LOCAL_RETURN_FUTURE(cpp2::KVGetResponse, future_get); } folly::Future GraphStorageLocalServer::future_put( const cpp2::KVPutRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ExecResponse, future_put); + LOCAL_RETURN_FUTURE(cpp2::ExecResponse, future_put); } folly::Future GraphStorageLocalServer::future_remove( const cpp2::KVRemoveRequest& request) { - LOCAL_RETURN_FUTURE(threadManager_, cpp2::ExecResponse, future_remove); + LOCAL_RETURN_FUTURE(cpp2::ExecResponse, future_remove); } } // namespace nebula::storage