pdns_recursor crashes with "Exception: Error closing socket: Connection reset by peer" message #192

Closed
Habbie opened this Issue Apr 26, 2013 · 1 comment

Projects

None yet

1 participant

@Habbie
Member
Habbie commented Apr 26, 2013

I'm running pdns_recursor on FreeBSD 6.3-RELEASE, i386 platform.
Suddenly it has stopped working with diagnostics below:

Jul 30 09:09:07 ns pdns_recursor[93705]: Exception: Error closing socket: Connection reset by peer

Digging through the code in file unix_utility.cc reveals this function:

int Utility::closesocket( Utility::sock_t socket )
{
int ret=::close(socket);
if(ret < 0)
throw AhuException("Error closing socket: "+stringerror());
return ret;

}

It seems to me that remote party sends a TCP RST during the small period of time between last recv() from this TCP socket and closing the socket by pdn_recursor, may be due to timer expired. While there is a very small probability for this scenario, it should be handled properly, especially on busy servers, serving hundreds DNS-queries per second.[[BR]]

There are at least three ways to do it:[[BR]]

  • call a getsockopt with SO_ERROR option specified just before calling close(). It will clear any error condition on socket, if any. Yes, it will eat more precious cpu resources. [[BR]]
  • simple ignore at least ECONNRESET error returned by close(). But it is unclear for me, if socket will be actually closed by some underlying OS code, or not. [[BR]]
  • probably. the best way is to handle ECONNRESET after an attempt to close socket by calling getsockopt() and then close() again. [[BR]]

Unfortunately, it will be hard to test any workaround applied, because it is very unlikely, that this bug will occur very often. It took something like three months of running pdns_recursor on six DNS-servers 24x7 to catch one :-)

WBR,[[BR]]

Andrei Poelov[[BR]]

apoelov at mail dot ru

@Habbie Habbie was assigned Apr 26, 2013
@Habbie Habbie closed this Apr 26, 2013
@Habbie
Member
Habbie commented Apr 26, 2013

Author: ahu
Fixed in cs 1280, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment