diff options
author | Shukang Zhou <shukang@google.com> | 2021-05-11 15:46:46 -0700 |
---|---|---|
committer | Shukang Zhou <shukang@google.com> | 2021-05-13 16:34:12 -0700 |
commit | fcecb51d25341dc00a016f42da3e442741d259ae (patch) | |
tree | 4282553376c887080b6327883e2e7b8ace7c9568 | |
parent | 51a40c63bbf10cdc5a0725740c1fbaf1c426b793 (diff) | |
download | grpc-grpc-fcecb51d25341dc00a016f42da3e442741d259ae.tar.gz |
[GRPC] Dup the provided fd for full ownershipstudio-2023.1.1-patch2studio-2023.1.1-patch1studio-2023.1.1-canary3studio-2023.1.1-canary11studio-2023.1.1-beta05studio-2023.1.1studio-2022.3.1-rc1studio-2022.3.1-canary8studio-2022.3.1-canary1studio-2022.3.1-beta2studio-2022.3.1studio-2022.2.1-canary7studio-2022.2.1-canary2studio-2022.2.1-canary10studio-2022.2.1-beta5studio-2022.2.1-beta1studio-2022.2.1studio-2022.1.1-rc3studio-2022.1.1-canary2studio-2022.1.1-canarystudio-2022.1.1-beta4studio-2022.1.1-beta2studio-2022.1.1studio-2021.3.1-betastudio-2021.3.1studio-2021.2.1-patch2studio-2021.2.1-patch1studio-2021.2.1studio-mainstudio-canarystudio-betastudio-2022.1.1-canary
Bug: 186054748
Test: manual; used logs to verify the fix
Change-Id: Ic3e387f8c5b222e0cfb35718921266f7ef7cdc5a
-rw-r--r-- | src/core/lib/iomgr/socket_utils_common_posix.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index 8db2c67c9e..39eb7883fd 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -431,12 +431,20 @@ grpc_error* grpc_create_dualstack_socket_using_factory( family = AF_INET; } *dsmode = family == AF_INET ? GRPC_DSMODE_IPV4 : GRPC_DSMODE_NONE; - // Special handling for Android Studio Profilers. + // Special handling for Android Studio Profilers (checking for '&'). // Check whether a connected fd is already provided by the caller of gRPC. if (family == AF_UNIX && addr->sa_data[0] == '&') { - // Use the provided connected fd directly. - *newfd = atoi(&addr->sa_data[1]); - } else { + // Make a copy of the provided connected fd. The ownership of the input fd + // is not transferred. gRPC library always assumes the ownership of the + // socket's fd, and will call close() over them when needed. Therefore, + // a copy is needed so gRPC can gracefully control the lifetime of the fd. + int input_fd = atoi(&addr->sa_data[1]); + int duped_fd = dup(input_fd); + *newfd = duped_fd; + gpr_log(GPR_DEBUG, "fd-based target: input_fd=%d, duped_fd=%d", input_fd, + duped_fd); + } // End of special handling for Android Studio Profilers + else { *newfd = create_socket(factory, family, type, protocol); } return error_for_fd(*newfd, resolved_addr); |