[init] Keep gRPC initialized until TCP destruction completes (#29852)

We've seen a case internally whereby TCP destruction can be delayed
behind grpc_shutdown, leading to crashes.
pull/29855/head
Craig Tiller 3 years ago committed by GitHub
parent 93207dbd87
commit 34d863b9c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/core/lib/iomgr/tcp_posix.cc

@ -39,6 +39,7 @@
#include <algorithm>
#include <unordered_map>
#include <grpc/grpc.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -357,10 +358,19 @@ using grpc_core::TcpZerocopySendCtx;
using grpc_core::TcpZerocopySendRecord;
namespace {
// Keep grpc initialized whilst there are TCP connections.
// This should not get ported to EventEngine!
class KeepGrpcInitializedForTCP {
public:
KeepGrpcInitializedForTCP() { grpc_init(); }
~KeepGrpcInitializedForTCP() { grpc_shutdown(); }
};
struct grpc_tcp {
grpc_tcp(int max_sends, size_t send_bytes_threshold)
: tcp_zerocopy_send_ctx(max_sends, send_bytes_threshold) {}
grpc_endpoint base;
GPR_NO_UNIQUE_ADDRESS KeepGrpcInitializedForTCP grpc_init_keep_alive;
grpc_fd* em_fd;
int fd;
/* Used by the endpoint read function to distinguish the very first read call

Loading…
Cancel
Save