Skip to content

Commit a11381b

Browse files
authored
Merge pull request #11994 from velconia/fix_grpc_destroy_bug
Fix grpc destroy bug
2 parents 938920c + cee8731 commit a11381b

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

cmake/external/grpc.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ExternalProject_Add(
5050
UPDATE_COMMAND ""
5151
CONFIGURE_COMMAND ""
5252
BUILD_IN_SOURCE 1
53+
PATCH_COMMAND git apply ${PADDLE_SOURCE_DIR}/patches/grpc/fix_too_early_destory.patch
5354
# NOTE(yuyang18):
5455
# Disable -Werror, otherwise the compile will fail in MacOS.
5556
# It seems that we cannot configure that by make command.

paddle/fluid/operators/distributed/grpc_client.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ GRPCClient::~GRPCClient() {
5959
for (auto& it : channels_) {
6060
it.second.reset();
6161
}
62+
channels_.clear();
6263
}
64+
6365
client_thread_->join();
6466
}
6567

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
diff --git a/include/grpcpp/impl/codegen/completion_queue.h b/include/grpcpp/impl/codegen/completion_queue.h
2+
index 80c7c41982..3f7d8a7714 100644
3+
--- a/include/grpcpp/impl/codegen/completion_queue.h
4+
+++ b/include/grpcpp/impl/codegen/completion_queue.h
5+
@@ -32,6 +32,8 @@
6+
#ifndef GRPCPP_IMPL_CODEGEN_COMPLETION_QUEUE_H
7+
#define GRPCPP_IMPL_CODEGEN_COMPLETION_QUEUE_H
8+
9+
+#include <typeinfo>
10+
+
11+
#include <grpc/impl/codegen/atm.h>
12+
#include <grpcpp/impl/codegen/completion_queue_tag.h>
13+
#include <grpcpp/impl/codegen/core_codegen_interface.h>
14+
@@ -106,7 +108,9 @@ class CompletionQueue : private GrpcLibraryCodegen {
15+
16+
/// Destructor. Destroys the owned wrapped completion queue / instance.
17+
~CompletionQueue() {
18+
- g_core_codegen_interface->grpc_completion_queue_destroy(cq_);
19+
+ if (typeid(*g_core_codegen_interface).hash_code() != typeid(CoreCodegenInterface).hash_code()) {
20+
+ g_core_codegen_interface->grpc_completion_queue_destroy(cq_);
21+
+ }
22+
}
23+
24+
/// Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT.
25+
diff --git a/include/grpcpp/impl/codegen/grpc_library.h b/include/grpcpp/impl/codegen/grpc_library.h
26+
index 17c904d71a..a092b2204d 100644
27+
--- a/include/grpcpp/impl/codegen/grpc_library.h
28+
+++ b/include/grpcpp/impl/codegen/grpc_library.h
29+
@@ -19,6 +19,8 @@
30+
#ifndef GRPCPP_IMPL_CODEGEN_GRPC_LIBRARY_H
31+
#define GRPCPP_IMPL_CODEGEN_GRPC_LIBRARY_H
32+
33+
+#include <typeinfo>
34+
+
35+
#include <grpcpp/impl/codegen/core_codegen_interface.h>
36+
37+
namespace grpc {
38+
@@ -47,7 +49,8 @@ class GrpcLibraryCodegen {
39+
}
40+
}
41+
virtual ~GrpcLibraryCodegen() {
42+
- if (grpc_init_called_) {
43+
+ if (grpc_init_called_ &&
44+
+ typeid(*g_glip).hash_code() != typeid(GrpcLibraryInterface).hash_code()) {
45+
GPR_CODEGEN_ASSERT(g_glip &&
46+
"gRPC library not initialized. See "
47+
"grpc::internal::GrpcLibraryInitializer.");

0 commit comments

Comments
 (0)