Skip to content

Commit

Permalink
Problem: getifaddrs can fail with ECONNREFUSED
Browse files Browse the repository at this point in the history
getifaddrs() can fail transiently with ECONNREFUSED on Linux.
This has been observed with Linux 3.10 when multiple processes
call zmq::tcp_address_t::resolve_nic_name() simultaneously.

Before asserting in this case, make 10 attempts, with exponential
backoff, given by (1 msec * 2^i), where i is the attempt number.

Fixes zeromq#2051
  • Loading branch information
garlick committed Jul 20, 2016
1 parent d44ef4f commit d090a87
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/tcp_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,16 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
{
// Get the addresses.
ifaddrs *ifa = NULL;
const int rc = getifaddrs (&ifa);
int rc;
const int max_attempts = 10;
const int backoff_msec = 1;
for (int i = 0; i < max_attempts; i++) {
rc = getifaddrs (&ifa);
if (rc == 0 || (rc < 0 && errno != ECONNREFUSED))
break;
usleep ((backoff_msec << i) * 1000);
}

if (rc != 0 && errno == EINVAL) {
// Windows Subsystem for Linux compatibility
LIBZMQ_UNUSED (nic_);
Expand Down

0 comments on commit d090a87

Please sign in to comment.