From f625d40d445aba8ad5dfe4965669ea1fb5e95ceb Mon Sep 17 00:00:00 2001 From: Wang Zhiyong Date: Wed, 9 Oct 2024 19:27:35 +0800 Subject: [PATCH] Fix lgraph_cli hang after a error query (#692) * fix lgraph_cli exception * add auth error log * fix cpplint * update tabulate version --- .../tugraph-compile-arm64v8-centos7-Dockerfile | 4 ++-- ci/images/tugraph-compile-centos7-Dockerfile | 4 ++-- ci/images/tugraph-compile-centos8-Dockerfile | 4 ++-- .../tugraph-compile-ubuntu18.04-Dockerfile | 4 ++-- src/bolt/pack_stream.h | 4 ++++ src/server/bolt_handler.cpp | 3 ++- toolkits/lgraph_cli.cpp | 18 ++++++++++++++++++ 7 files changed, 32 insertions(+), 9 deletions(-) diff --git a/ci/images/tugraph-compile-arm64v8-centos7-Dockerfile b/ci/images/tugraph-compile-arm64v8-centos7-Dockerfile index 165ebabc60..c8d6a06681 100644 --- a/ci/images/tugraph-compile-arm64v8-centos7-Dockerfile +++ b/ci/images/tugraph-compile-arm64v8-centos7-Dockerfile @@ -329,8 +329,8 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/graphar/Gr # tabulate # if it is not accessible, replace it with the link below # https://github.com/p-ranav/tabulate/archive/refs/tags/v1.5.tar.gz -RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-d553e5.tar.gz \ - && tar zxf tabulate-d553e5.tar.gz && cp -rf tabulate-d553e5/include/tabulate /usr/local/include \ +RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-3a5830.tar.gz \ + && tar zxf tabulate-3a5830.tar.gz && cp -rf tabulate/include/tabulate /usr/local/include \ && rm -rf /tabulate* RUN sed -i '3 s/-lgomp/-l:libgomp.a/' /usr/local/lib64/libgomp.spec diff --git a/ci/images/tugraph-compile-centos7-Dockerfile b/ci/images/tugraph-compile-centos7-Dockerfile index 21238ac7f8..498eed3eca 100644 --- a/ci/images/tugraph-compile-centos7-Dockerfile +++ b/ci/images/tugraph-compile-centos7-Dockerfile @@ -339,8 +339,8 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/graphar/Gr # tabulate # if it is not accessible, replace it with the link below # https://github.com/p-ranav/tabulate/archive/refs/tags/v1.5.tar.gz -RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-d553e5.tar.gz \ - && tar zxf tabulate-d553e5.tar.gz && cp -rf tabulate-d553e5/include/tabulate /usr/local/include \ +RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-3a5830.tar.gz \ + && tar zxf tabulate-3a5830.tar.gz && cp -rf tabulate/include/tabulate /usr/local/include \ && rm -rf /tabulate* RUN sed -i '3 s/-lgomp/-l:libgomp.a/' /usr/local/lib64/libgomp.spec diff --git a/ci/images/tugraph-compile-centos8-Dockerfile b/ci/images/tugraph-compile-centos8-Dockerfile index a3a72cf1a3..6879f9c025 100644 --- a/ci/images/tugraph-compile-centos8-Dockerfile +++ b/ci/images/tugraph-compile-centos8-Dockerfile @@ -327,8 +327,8 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/graphar/Gr # tabulate # if it is not accessible, replace it with the link below # https://github.com/p-ranav/tabulate/archive/refs/tags/v1.5.tar.gz -RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-d553e5.tar.gz \ - && tar zxf tabulate-d553e5.tar.gz && cp -rf tabulate-d553e5/include/tabulate /usr/local/include \ +RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-3a5830.tar.gz \ + && tar zxf tabulate-3a5830.tar.gz && cp -rf tabulate/include/tabulate /usr/local/include \ && rm -rf /tabulate* RUN sed -i '3 s/-lgomp/-l:libgomp.a/' /usr/local/lib64/libgomp.spec diff --git a/ci/images/tugraph-compile-ubuntu18.04-Dockerfile b/ci/images/tugraph-compile-ubuntu18.04-Dockerfile index 925b4d1a6d..594ab07d20 100644 --- a/ci/images/tugraph-compile-ubuntu18.04-Dockerfile +++ b/ci/images/tugraph-compile-ubuntu18.04-Dockerfile @@ -325,8 +325,8 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/graphar/Gr # tabulate # if it is not accessible, replace it with the link below # https://github.com/p-ranav/tabulate/archive/refs/tags/v1.5.tar.gz -RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-d553e5.tar.gz \ - && tar zxf tabulate-d553e5.tar.gz && cp -rf tabulate-d553e5/include/tabulate /usr/local/include \ +RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-3a5830.tar.gz \ + && tar zxf tabulate-3a5830.tar.gz && cp -rf tabulate/include/tabulate /usr/local/include \ && rm -rf /tabulate* RUN sed -i '3 s/-lgomp/-l:libgomp.a/' /usr/local/lib64/libgomp.spec diff --git a/src/bolt/pack_stream.h b/src/bolt/pack_stream.h index e16f5eef69..e482e11f62 100644 --- a/src/bolt/pack_stream.h +++ b/src/bolt/pack_stream.h @@ -221,6 +221,10 @@ class PackStream { AppendStructMessage(BoltMsg::Ignored); } + void AppendReset() { + AppendStructMessage(BoltMsg::Reset); + } + void AppendFailure(const std::unordered_map& meta) { AppendStructMessage(BoltMsg::Failure, meta); } diff --git a/src/server/bolt_handler.cpp b/src/server/bolt_handler.cpp index 60a320c919..c9d1f8398e 100644 --- a/src/server/bolt_handler.cpp +++ b/src/server/bolt_handler.cpp @@ -259,7 +259,8 @@ std::function(val.at("credentials")); auto galaxy = BoltServer::Instance().StateMachine()->GetGalaxy(); if (!galaxy->ValidateUser(principal, credentials)) { - LOG_ERROR() << "Bolt authentication failed"; + LOG_ERROR() << FMA_FMT( + "Bolt authentication failed, user:{}, password:{}", principal, credentials); bolt::PackStream ps; ps.AppendFailure({{"code", "error"}, {"message", "Authentication failed"}}); diff --git a/toolkits/lgraph_cli.cpp b/toolkits/lgraph_cli.cpp index 7459c19bc5..e4a80f263c 100644 --- a/toolkits/lgraph_cli.cpp +++ b/toolkits/lgraph_cli.cpp @@ -283,6 +283,24 @@ int main(int argc, char** argv) { asio::write(socket, asio::const_buffer(ps.ConstBuffer().data(), ps.ConstBuffer().size())); bool ret = FetchRecords(socket, hydrator, of); + if (!ret) { + // reset connection + ps.Reset(); + ps.AppendReset(); + asio::write(socket, asio::const_buffer( + ps.ConstBuffer().data(), ps.ConstBuffer().size())); + while (true) { + auto m = ReadMessage(socket, hydrator); + if (m.type() == typeid(bolt::Success*)) { + break; + } else if (m.type() == typeid(bolt::Ignored*)) { + continue; + } else { + LOG_ERROR() << "unexpected bolt msg after reset"; + return -1; + } + } + } if (is_terminal && ret) { linenoiseHistoryAdd(statement.c_str()); linenoiseHistorySave(history_file);