Permalink
Browse files

fall back to central bind if reuseport bind fails; improves #1715

  • Loading branch information...
1 parent 96f4bce commit ed3afdfc8f4bb84521f081d10fed128e91ec90b3 @Habbie Habbie committed Sep 16, 2014
Showing with 8 additions and 2 deletions.
  1. +6 −1 pdns/common_startup.cc
  2. +2 −1 pdns/nameserver.cc
@@ -256,7 +256,12 @@ void *qthread(void *number)
// other than the first one.
if( number != NULL && NS->canReusePort() ) {
L<<Logger::Notice<<"Starting new listen thread on the same IPs/ports using SO_REUSEPORT"<<endl;
- NS = new UDPNameserver( true );
+ try {
+ NS = new UDPNameserver( true );
+ } catch(PDNSException &e) {
+ L<<Logger::Error<<"Unable to reuse port, falling back to original bind"<<endl;
+ NS = N;
+ }
}
for(;;) {
View
@@ -135,12 +135,13 @@ void UDPNameserver::bindIPv4()
g_localaddresses.push_back(locala);
if(::bind(s, (sockaddr*)&locala, locala.getSocklen()) < 0) {
+ string binderror = strerror(errno);
close(s);
if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-address-nonexist-fail") ) {
L<<Logger::Error<<"IPv4 Address " << localname << " does not exist on this server - skipping UDP bind" << endl;
continue;
} else {
- L<<Logger::Error<<"binding UDP socket to '"+locala.toStringWithPort()+": "<<strerror(errno)<<endl;
+ L<<Logger::Error<<"binding UDP socket to '"+locala.toStringWithPort()+"': "<<binderror<<endl;
throw PDNSException("Unable to bind to UDP socket");
}
}

0 comments on commit ed3afdf

Please sign in to comment.