From 42284424acd2ba4ba649599984592f5d2eade919 Mon Sep 17 00:00:00 2001 From: AJ Heller Date: Fri, 17 Nov 2023 13:21:21 -0800 Subject: [PATCH] [EventEngine] Produce better error logs on `bind` failures (#35004) Seeing a rare flake where a fixture address is already in use. This PR adds sockaddr->string conversion for the address, in case some of this address is being truncated before attempting to bind. It's very odd to see this exact-time-based address string generated twice in succession. `E1116 21:34:56.431768483 17 chttp2_server.cc:1051] UNKNOWN:No address added out of total 1 resolved for 'unix-abstract:grpc_fullstack_test.%00.17.974.661825339.14468088171934000544.7442035989947845277' {created_time:"2023-11-16T21:34:56.431729283+00:00", children:[FAILED_PRECONDITION:Error in bind: Address already in use]} ` https://source.cloud.google.com/results/invocations/48ee2e26-9341-46ec-9761-35939b73f3f8/targets/%2F%2Ftest%2Fcore%2Fend2end:retry_transparent_max_concurrent_streams_test@poller%3Dpoll/log Closes #35004 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35004 from drfloob:better-error-on-bind-failure d12d5f86326fdf411fed51093998e09121535c39 PiperOrigin-RevId: 583472016 --- .../posix_engine/posix_engine_listener_utils.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc index 8c2745c02b27e..ed2321b297100 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc @@ -25,6 +25,8 @@ #include "absl/cleanup/cleanup.h" #include "absl/status/status.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/str_replace.h" #include #include @@ -44,8 +46,6 @@ #include // IWYU pragma: keep #include // IWYU pragma: keep #include // IWYU pragma: keep - -#include "absl/strings/str_cat.h" #endif namespace grpc_event_engine { @@ -176,8 +176,16 @@ absl::Status PrepareSocket(const PosixTcpOptions& options, GRPC_FD_SERVER_LISTENER_USAGE, options)); if (bind(fd, socket.addr.address(), socket.addr.size()) < 0) { + auto sockaddr_str = ResolvedAddressToString(socket.addr); + if (!sockaddr_str.ok()) { + gpr_log(GPR_ERROR, "Could not convert sockaddr to string: %s", + sockaddr_str.status().ToString().c_str()); + sockaddr_str = ""; + } + sockaddr_str = absl::StrReplaceAll(*sockaddr_str, {{"\0", "@"}}); return absl::FailedPreconditionError( - absl::StrCat("Error in bind: ", std::strerror(errno))); + absl::StrCat("Error in bind for address '", *sockaddr_str, + "': ", std::strerror(errno))); } if (listen(fd, GetMaxAcceptQueueSize()) < 0) {