Skip to content

Commit

Permalink
[EventEngine] Produce better error logs on bind failures (grpc#35004)
Browse files Browse the repository at this point in the history
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 grpc#35004

COPYBARA_INTEGRATE_REVIEW=grpc#35004 from drfloob:better-error-on-bind-failure d12d5f8
PiperOrigin-RevId: 583472016
  • Loading branch information
drfloob authored and copybara-github committed Nov 17, 2023
1 parent 4ecead5 commit 4228442
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <grpc/event_engine/event_engine.h>
#include <grpc/support/log.h>
Expand All @@ -44,8 +46,6 @@
#include <netinet/in.h> // IWYU pragma: keep
#include <sys/socket.h> // IWYU pragma: keep
#include <unistd.h> // IWYU pragma: keep

#include "absl/strings/str_cat.h"
#endif

namespace grpc_event_engine {
Expand Down Expand Up @@ -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 = "<unparsable>";
}
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) {
Expand Down

0 comments on commit 4228442

Please sign in to comment.