Skip to content

Commit

Permalink
dnsdist: Prevent dangling TCP fd in case setupTCPDownstream() fails
Browse files Browse the repository at this point in the history
Remove the closed socket descriptor from the sockets map.
Otherwise, if an exception occurs in setupTCPDownstream(), we might
try to use it and close it again later, not knowing it has been
reassigned to another socket or, worse, to a TCP acceptor pipe.
  • Loading branch information
rgacogne committed Mar 29, 2016
1 parent d1f9407 commit 65d7f2b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pdns/dnsdist-tcp.cc
Expand Up @@ -358,6 +358,8 @@ void* tcpClientThread(int pipefd)
if(!sendNonBlockingMsgLen(dsock, dq.len, ds->tcpSendTimeout, ds->remote, ds->sourceAddr, ds->sourceItf)) {
vinfolog("Downstream connection to %s died on us, getting a new one!", ds->getName());
close(dsock);
dsock=-1;
sockets.erase(ds->remote);
sockets[ds->remote]=dsock=setupTCPDownstream(ds);
downstream_failures++;
goto retry;
Expand All @@ -374,6 +376,8 @@ void* tcpClientThread(int pipefd)
catch(const runtime_error& e) {
vinfolog("Downstream connection to %s died on us, getting a new one!", ds->getName());
close(dsock);
dsock=-1;
sockets.erase(ds->remote);
sockets[ds->remote]=dsock=setupTCPDownstream(ds);
downstream_failures++;
goto retry;
Expand All @@ -382,6 +386,8 @@ void* tcpClientThread(int pipefd)
if(!getNonBlockingMsgLen(dsock, &rlen, ds->tcpRecvTimeout)) {
vinfolog("Downstream connection to %s died on us phase 2, getting a new one!", ds->getName());
close(dsock);
dsock=-1;
sockets.erase(ds->remote);
sockets[ds->remote]=dsock=setupTCPDownstream(ds);
downstream_failures++;
goto retry;
Expand Down

0 comments on commit 65d7f2b

Please sign in to comment.