Skip to content

Commit

Permalink
Merge pull request #3634 from rgacogne/dnsdist-dangling-tcp-fd
Browse files Browse the repository at this point in the history
dnsdist: Prevent dangling TCP fd in case setupTCPDownstream() fails
  • Loading branch information
rgacogne committed Apr 1, 2016
2 parents b409153 + 65d7f2b commit 13506cd
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 13506cd

Please sign in to comment.