Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log message if bind(2) fails when looking up address for hostname #191

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions gloo/transport/tcp/device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ static void lookupAddrForHostname(struct attr& attr) {
hints.ai_family = attr.ai_family;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo* result;
int bind_rv = 0;
int bind_errno = 0;
std::string bind_addr;
auto rv = getaddrinfo(attr.hostname.data(), nullptr, &hints, &result);
GLOO_ENFORCE_NE(rv, -1);
struct addrinfo* rp;
Expand All @@ -105,8 +108,10 @@ static void lookupAddrForHostname(struct attr& attr) {
continue;
}

rv = bind(fd, rp->ai_addr, rp->ai_addrlen);
if (rv == -1) {
bind_rv = bind(fd, rp->ai_addr, rp->ai_addrlen);
if (bind_rv == -1) {
bind_errno = errno;
bind_addr = Address(rp->ai_addr, rp->ai_addrlen).str();
close(fd);
continue;
}
Expand All @@ -120,7 +125,17 @@ static void lookupAddrForHostname(struct attr& attr) {
break;
}

// Check that we found an address we were able to bind to
// If the final call to bind(2) failed, raise error saying so.
GLOO_ENFORCE(
bind_rv == 0,
"Unable to find address for ",
attr.hostname,
"; bind(2) for ",
bind_addr,
" failed with: ",
strerror(bind_errno));

// Verify that we were able to find an address in the first place.
GLOO_ENFORCE(
rp != nullptr,
"Unable to find address for: ",
Expand Down