mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-31 14:39:55 +01:00
Problem: getifaddrs can fail with ECONNREFUSED
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 #2051
This commit is contained in:
parent
d44ef4fa5f
commit
d090a871bc
@ -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_);
|
||||
|
Loading…
x
Reference in New Issue
Block a user