Skip to content

Commit 0c62b3f

Browse files
authored
fix grpc bind error caused program crash && add exception handler for java wrapper (#85)
* fix grpc bind error caused program crash * add exception handler for java wrapper * fix log caused exit coredump * add exception handler for python wrapper * update workflow * fix gateway exist coredump * optimize version print
1 parent e216139 commit 0c62b3f

File tree

37 files changed

+5227
-827
lines changed

37 files changed

+5227
-827
lines changed

.github/workflows/cpp_full_node_workflow.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ jobs:
6666
export GCC='gcc-10'
6767
export CXX='g++-10'
6868
sudo bash -x cpp/tools/install_depends.sh -o ubuntu
69-
mkdir -p cpp/build && cd cpp/build && cmake -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
69+
mkdir -p cpp/build && cd cpp/build && cmake -DBUILD_STATIC=ON -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
7070
make -j3
7171
- name: Build for macOS
7272
if: runner.os == 'macOS'
7373
run: |
7474
bash -x cpp/tools/install_depends.sh -o macos
75-
mkdir -p cpp/build && cd cpp/build && cmake -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
75+
mkdir -p cpp/build && cd cpp/build && cmake -DBUILD_STATIC=ON -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
7676
make -j3
7777
- uses: actions/upload-artifact@v4
7878
if: runner.os == 'macOS'
@@ -163,7 +163,7 @@ jobs:
163163
rm -rf python
164164
mkdir -p cpp/build
165165
cd cpp/build
166-
cmake3 -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
166+
cmake3 -DBUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
167167
- name: FreeDiskSpace
168168
run: |
169169
df -lh

.github/workflows/cpp_toolkit_workflow.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
with:
4141
toolchain: nightly-2022-07-28
4242
override: true
43+
- name: Prepare python
44+
if: runner.os == 'Windows'
45+
uses: actions/setup-python@v5
46+
with:
47+
python-version: '3.8'
4348
- name: Prepare vcpkg
4449
if: runner.os != 'Windows'
4550
uses: friendlyanon/setup-vcpkg@v1
@@ -65,7 +70,7 @@ jobs:
6570
- name: Build for windows
6671
if: runner.os == 'Windows'
6772
run: |
68-
mkdir -p cpp/build && cd cpp/build && cmake -G "Visual Studio 16 2019" -A x64 -DBUILD_PYTHON=OFF -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DBUILD_WEDPR_TOOLKIT=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static -DVCPKG_HOST_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake .. && MSBuild /version && MSBuild WeDPR-Component.sln /p:Configuration=Release /p:Platform=x64
73+
mkdir -p cpp/build && cd cpp/build && cmake -G "Visual Studio 16 2019" -A x64 -DBUILD_PYTHON=ON -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DBUILD_WEDPR_TOOLKIT=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static -DVCPKG_HOST_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake .. && MSBuild /version && MSBuild WeDPR-Component.sln /p:Configuration=Release /p:Platform=x64
6974
- name: Build for linux
7075
if: runner.os == 'Linux'
7176
run: |

cpp/cmake/CompilerSettings.cmake

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
1717
# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "/usr/bin/time")
1818
# set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "/usr/bin/time")
1919
# Use ISO C++17 standard language.
20-
set(CMAKE_CXX_FLAGS "-pthread -fPIC -fexceptions")
2120
# set(CMAKE_CXX_VISIBILITY_PRESET hidden)
2221
# Enables all the warnings about constructions that some users consider questionable,
2322
# and that are easy to avoid. Also enable some extra warning flags that are not
@@ -75,11 +74,16 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
7574

7675
option(USE_LD_GOLD "Use GNU gold linker" ON)
7776
if (USE_LD_GOLD)
78-
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
79-
if ("${LD_VERSION}" MATCHES "GNU gold")
80-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
81-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold")
82-
endif ()
77+
if("${LINKER}" MATCHES "gold")
78+
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
79+
if("${LD_VERSION}" MATCHES "GNU gold")
80+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
81+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold")
82+
endif()
83+
elseif("${LINKER}" MATCHES "mold")
84+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=mold")
85+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=mold")
86+
endif()
8387
endif ()
8488

8589
# Additional GCC-specific compiler settings.
@@ -91,15 +95,32 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
9195
if (NOT (GCC_VERSION VERSION_GREATER ${GCC_MIN_VERSION} OR GCC_VERSION VERSION_EQUAL ${GCC_MIN_VERSION}))
9296
message(FATAL_ERROR "${PROJECT_NAME} requires g++ ${GCC_MIN_VERSION} or greater. Current is ${GCC_VERSION}")
9397
endif ()
94-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE}")
95-
set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS} ${MARCH_TYPE}")
98+
if(BUILD_STATIC)
99+
# solve multiple definition of `__lll_lock_wait_private'
100+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE} -ftree-parallelize-loops=2 -flto")
101+
else()
102+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE}")
103+
endif()
104+
set(CMAKE_C_FLAGS "-std=c99 -fexceptions ${CMAKE_C_FLAGS} ${MARCH_TYPE}")
96105

97106
# Strong stack protection was only added in GCC 4.9.
98107
# Use it if we have the option to do so.
99108
# See https://lwn.net/Articles/584225/
100-
if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
101-
add_compile_options(-fstack-protector-strong)
102-
add_compile_options(-fstack-protector)
109+
add_compile_options(-fstack-protector-strong)
110+
add_compile_options(-fstack-protector)
111+
112+
add_compile_options(-fPIC)
113+
add_compile_options(-Wno-error=nonnull)
114+
add_compile_options(-foptimize-sibling-calls)
115+
add_compile_options(-Wno-stringop-overflow)
116+
add_compile_options(-Wno-restrict)
117+
add_compile_options(-Wno-error=format-truncation)
118+
119+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
120+
add_compile_options(-Wno-stringop-overread)
121+
add_compile_options(-Wno-maybe-uninitialized)
122+
add_compile_options(-Wno-array-bounds)
123+
add_compile_options(-Wno-aggressive-loop-optimizations)
103124
endif()
104125
# Additional Clang-specific compiler settings.
105126
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")

cpp/cmake/ProjectTCMalloc.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ ExternalProject_Add(gperftools
2828
)
2929

3030
ExternalProject_Get_Property(gperftools SOURCE_DIR)
31-
add_library(TCMalloc INTERFACE IMPORTED)
31+
add_library(TCMalloc STATIC IMPORTED GLOBAL)
3232

3333
set(TCMALLOC_INCLUDE_DIR ${SOURCE_DIR}/include/)
3434
set(TCMALLOC_LIBRARY ${SOURCE_DIR}/.libs/${TCMALLOC_LIB_NAME})
3535
file(MAKE_DIRECTORY ${TCMALLOC_INCLUDE_DIR}) # Must exist.
3636

37-
set_property(TARGET TCMalloc PROPERTY INTERFACE_LINK_LIBRARIES ${TCMALLOC_LIBRARY})
37+
set_property(TARGET TCMalloc PROPERTY IMPORTED_LOCATION ${TCMALLOC_LIBRARY})
3838
set_property(TARGET TCMalloc PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${TCMALLOC_INCLUDE_DIR})
3939

4040
add_dependencies(TCMalloc gperftools)

cpp/ppc-framework/protocol/GrpcConfig.h

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,6 @@
2626

2727
namespace ppc::protocol
2828
{
29-
class GrpcServerConfig
30-
{
31-
public:
32-
using Ptr = std::shared_ptr<GrpcServerConfig>;
33-
GrpcServerConfig() = default;
34-
GrpcServerConfig(EndPoint endPoint, bool enableHealthCheck)
35-
: m_endPoint(std::move(endPoint)), m_enableHealthCheck(enableHealthCheck)
36-
{}
37-
std::string listenEndPoint() const { return m_endPoint.listenEndPoint(); }
38-
39-
void setEndPoint(EndPoint endPoint) { m_endPoint = endPoint; }
40-
void setEnableHealthCheck(bool enableHealthCheck) { m_enableHealthCheck = enableHealthCheck; }
41-
42-
EndPoint const& endPoint() const { return m_endPoint; }
43-
EndPoint& mutableEndPoint() { return m_endPoint; }
44-
bool enableHealthCheck() const { return m_enableHealthCheck; }
45-
46-
protected:
47-
ppc::protocol::EndPoint m_endPoint;
48-
bool m_enableHealthCheck = true;
49-
};
5029
class GrpcConfig
5130
{
5231
public:
@@ -71,10 +50,22 @@ class GrpcConfig
7150

7251
void setMaxSendMessageSize(uint64_t maxSendMessageSize)
7352
{
53+
if (maxSendMessageSize > c_maxMsgSize)
54+
{
55+
BOOST_THROW_EXCEPTION(
56+
WeDPRException() << bcos::errinfo_comment(
57+
"The MaxSendMessageSize limit is " + std::to_string(c_maxMsgSize)));
58+
}
7459
m_maxSendMessageSize = maxSendMessageSize;
7560
}
7661
void setMaxReceivedMessageSize(uint64_t maxReceivedMessageSize)
7762
{
63+
if (maxReceivedMessageSize > c_maxMsgSize)
64+
{
65+
BOOST_THROW_EXCEPTION(
66+
WeDPRException() << bcos::errinfo_comment(
67+
"The MaxReceivedMessageSize limit is " + std::to_string(c_maxMsgSize)));
68+
}
7869
m_maxReceivedMessageSize = maxReceivedMessageSize;
7970
}
8071

@@ -102,14 +93,53 @@ class GrpcConfig
10293
bool m_enableHealthCheck = true;
10394
std::string m_loadBalancePolicy = "round_robin";
10495
bool m_enableDnslookup = false;
96+
// Note: grpc use int to set the maxMsgSize
97+
uint64_t const c_maxMsgSize = INT_MAX;
10598

10699
// the max send message size in bytes
107-
uint64_t m_maxSendMessageSize = 1024 * 1024 * 1024;
100+
uint64_t m_maxSendMessageSize = c_maxMsgSize;
108101
// the max received message size in bytes
109-
uint64_t m_maxReceivedMessageSize = 1024 * 1024 * 1024;
102+
uint64_t m_maxReceivedMessageSize = c_maxMsgSize;
110103
int m_compressAlgorithm = 0;
111104
};
112105

106+
class GrpcServerConfig : public GrpcConfig
107+
{
108+
public:
109+
using Ptr = std::shared_ptr<GrpcServerConfig>;
110+
GrpcServerConfig() = default;
111+
GrpcServerConfig(EndPoint endPoint, bool enableHealthCheck)
112+
: m_endPoint(std::move(endPoint)), m_enableHealthCheck(enableHealthCheck)
113+
{}
114+
~GrpcServerConfig() override = default;
115+
116+
std::string listenEndPoint() const { return m_endPoint.listenEndPoint(); }
117+
118+
void setEndPoint(EndPoint endPoint) { m_endPoint = endPoint; }
119+
void setEnableHealthCheck(bool enableHealthCheck) { m_enableHealthCheck = enableHealthCheck; }
120+
121+
EndPoint const& endPoint() const { return m_endPoint; }
122+
EndPoint& mutableEndPoint() { return m_endPoint; }
123+
bool enableHealthCheck() const { return m_enableHealthCheck; }
124+
125+
uint64_t maxMsgSize() const { return m_maxMsgSize; }
126+
void setMaxMsgSize(uint64_t maxMsgSize)
127+
{
128+
if (maxMsgSize > c_maxMsgSize)
129+
{
130+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
131+
"The maxMsgSize limit is " + std::to_string(c_maxMsgSize)));
132+
}
133+
m_maxMsgSize = maxMsgSize;
134+
}
135+
136+
protected:
137+
ppc::protocol::EndPoint m_endPoint;
138+
bool m_enableHealthCheck = true;
139+
uint64_t m_maxMsgSize = c_maxMsgSize;
140+
};
141+
142+
113143
inline std::string printGrpcConfig(ppc::protocol::GrpcConfig::Ptr const& grpcConfig)
114144
{
115145
if (!grpcConfig)

cpp/wedpr-helper/libhelper/CommandHelper.cpp

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626

2727
using namespace ppc;
2828

29-
void ppc::printVersion()
29+
void ppc::printVersion(std::string const& binaryName)
3030
{
31-
std::cout << "PPCS-Core Version : " << PPC_PROJECT_VERSION << std::endl;
31+
std::cout << binaryName << " Version : " << PPC_PROJECT_VERSION << std::endl;
3232
std::cout << "Build Time : " << PPC_BUILD_TIME << std::endl;
3333
std::cout << "Build Type : " << PPC_BUILD_PLATFORM << "/" << PPC_BUILD_TYPE
3434
<< std::endl;
3535
std::cout << "Git Branch : " << PPC_BUILD_BRANCH << std::endl;
3636
std::cout << "Git Commit : " << PPC_COMMIT_HASH << std::endl;
3737
}
3838

39-
CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
39+
CommandLineParam ppc::initCommandLine(std::string const& binaryName, int argc, const char* argv[])
4040
{
4141
boost::program_options::options_description main_options("Usage of PPC");
4242
main_options.add_options()("help,h", "print help information")("version,v", "version of PPC")(
@@ -49,7 +49,7 @@ CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
4949
}
5050
catch (...)
5151
{
52-
printVersion();
52+
printVersion(binaryName);
5353
}
5454
/// help information
5555
if (vm.count("help") || vm.count("h"))
@@ -60,7 +60,7 @@ CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
6060
/// version information
6161
if (vm.count("version") || vm.count("v"))
6262
{
63-
printVersion();
63+
printVersion(binaryName);
6464
exit(0);
6565
}
6666
std::string configPath("./config.ini");
@@ -81,31 +81,3 @@ CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
8181
}
8282
return ppc::CommandLineParam{configPath};
8383
}
84-
85-
void ppc::initAppCommandLine(int argc, char* argv[])
86-
{
87-
boost::program_options::options_description main_options("Usage of PPC");
88-
main_options.add_options()("help,h", "print help information")("version,v", "version of PPC");
89-
boost::program_options::variables_map vm;
90-
try
91-
{
92-
boost::program_options::store(
93-
boost::program_options::parse_command_line(argc, argv, main_options), vm);
94-
}
95-
catch (...)
96-
{
97-
printVersion();
98-
}
99-
/// help information
100-
if (vm.count("help") || vm.count("h"))
101-
{
102-
std::cout << main_options << std::endl;
103-
exit(0);
104-
}
105-
/// version information
106-
if (vm.count("version") || vm.count("v"))
107-
{
108-
printVersion();
109-
exit(0);
110-
}
111-
}

cpp/wedpr-helper/libhelper/CommandHelper.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct CommandLineParam
2727
{
2828
std::string configFilePath;
2929
};
30-
void printVersion();
31-
CommandLineParam initCommandLine(int argc, const char* argv[]);
32-
void initAppCommandLine(int argc, char* argv[]);
30+
void printVersion(std::string const& binaryName);
31+
CommandLineParam initCommandLine(std::string const& binaryName, int argc, const char* argv[]);
3332
} // namespace ppc

cpp/wedpr-initializer/Initializer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ void Initializer::init(ppc::gateway::IGateway::Ptr const& gateway)
207207
INIT_LOG(INFO) << LOG_DESC("create bs mode ecdh psi success");
208208

209209
initMsgHandlers();
210-
211-
// add parallelism control for tbb
212-
tbb::global_control gc(
213-
tbb::global_control::max_allowed_parallelism, m_config->threadPoolSize());
214210
}
215211

216212
// init the msg-handlers

cpp/wedpr-main/air-node/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
int main(int argc, const char* argv[])
2424
{
25-
auto initializer = std::make_shared<ppc::node::AirNodeInitializer>();
26-
startProgram(argc, argv, "ppc-psi", initializer);
25+
std::string binaryName = "ppc-psi";
26+
auto initializer = std::make_shared<ppc::node::AirNodeInitializer>();
27+
auto ret = startProgram(argc, argv, binaryName, initializer);
28+
initializer.reset();
29+
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
30+
std::cout << "The " << binaryName << " program exit normally." << std::endl;
31+
return ret;
2732
}

cpp/wedpr-main/cem-node/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ int main(int argc, const char* argv[])
5353
auto initializer = std::make_shared<ppc::cem::CEMInitializer>();
5454
try
5555
{
56-
auto param = initCommandLine(argc, argv);
56+
auto param = initCommandLine("wedpr-cem", argc, argv);
5757
initializer->init(param.configFilePath);
5858
initializer->start();
5959
}
6060
catch (std::exception const& e)
6161
{
62-
printVersion();
62+
printVersion("wedpr-cem");
6363
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
6464
std::cout << "start ppc-cem failed, error:" << boost::diagnostic_information(e)
6565
<< std::endl;
6666
return -1;
6767
}
68-
printVersion();
68+
printVersion("wedpr-cem");
6969
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
7070
std::cout << "The ppc-cem is running..." << std::endl;
7171
while (!exitHandler.shouldExit())

0 commit comments

Comments
 (0)