From b05ef1b472cfa3597dda44075f3947abd565008b Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 21 Sep 2020 17:24:55 +0200 Subject: [PATCH] rec: Watch the descriptor again after an out-of-order read timeout It might be that there was no other incoming query on that connection and we timed out while the response had not been sent yet, but the client might want to re-use the connection after receving the response. We try to reset the TTD, but that might fail when the socket descriptor has already been removed. --- pdns/pdns_recursor.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 09663e3f99..4553101703 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1910,11 +1910,15 @@ static void startDoResolve(void *p) ttd.tv_sec += g_tcpTimeout; t_fdm->addReadFD(dc->d_socket, handleRunningTCPQuestion, dc->d_tcpConnection, &ttd); } else { - // fd might have been removed by read error code, so expect an exception + // fd might have been removed by read error code, or a read timeout, so expect an exception try { t_fdm->setReadTTD(dc->d_socket, ttd, g_tcpTimeout); } - catch (FDMultiplexerException &) { + catch (const FDMultiplexerException &) { + // but the FD was removed because of a timeout while we were sending a response, + // we need to re-arm it. If it was an error it will error again. + ttd.tv_sec += g_tcpTimeout; + t_fdm->addReadFD(dc->d_socket, handleRunningTCPQuestion, dc->d_tcpConnection, &ttd); } } } -- 2.47.2