Skip to content

Commit

Permalink
fall back to central bind if reuseport bind fails; improves #1715
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter van Dijk committed Sep 16, 2014
1 parent 96f4bce commit ed3afdf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pdns/common_startup.cc
Expand Up @@ -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(;;) {
Expand Down
3 changes: 2 additions & 1 deletion pdns/nameserver.cc
Expand Up @@ -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");
}
}
Expand Down

0 comments on commit ed3afdf

Please sign in to comment.