From: Bert Hubert Date: Tue, 18 Apr 2006 12:18:02 +0000 (+0000) Subject: fix timeouts of running TCP client queries - we shouldn't time them out while we... X-Git-Tag: rec-3-0~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a6ae6414509eb61c1c5be4547d2f063c8d88119e;p=pdns fix timeouts of running TCP client queries - we shouldn't time them out while we are still working! git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@722 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/mplexer.hh b/pdns/mplexer.hh index 62950448c..ce69b9e0a 100644 --- a/pdns/mplexer.hh +++ b/pdns/mplexer.hh @@ -77,6 +77,13 @@ public: d_readCallbacks[fd].d_ttd=tv; } + virtual boost::any& getReadParameter(int fd) + { + if(!d_readCallbacks.count(fd)) + throw FDMultiplexerException("attempt to look up data in multiplexer for unlisted fd "+boost::lexical_cast(fd)); + return d_readCallbacks[fd].d_parameter; + } + virtual std::vector > getTimeouts(const struct timeval& tv) { std::vector > ret; @@ -97,6 +104,7 @@ public: virtual std::string getName() = 0; + protected: typedef std::map callbackmap_t; callbackmap_t d_readCallbacks, d_writeCallbacks; diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 087c9ad8b..2ebfe5a6c 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -525,26 +525,13 @@ void startDoResolve(void *p) if(hadError) { g_fdm->removeReadFD(dc->d_socket); close(dc->d_socket); - // i->closeAndCleanup(); // XXX we don't remove ourselves from the list anymore } - else - ; // XXX FIXME, need to restore resetting connection to BYTE0 in case of noerror! - -#if 0 - for(vector::iterator i=g_tcpconnections.begin();i!=g_tcpconnections.end();++i) { - if(i->fd == dc->d_socket) { - if(hadError) { - i->closeAndCleanup(); - g_tcpconnections.erase(i); - } - else { - i->state=TCPConnection::BYTE0; - i->startTime=time(0); // needs to be current, TCP is slow anyhow - } - break; - } + else { + any_cast(g_fdm->getReadParameter(dc->d_socket)).state=TCPConnection::BYTE0; + struct timeval now; + gettimeofday(&now, 0); // needs to be updated + g_fdm->setReadTTD(dc->d_socket, now, g_tcpTimeout); } -#endif } if(!g_quiet) { @@ -645,8 +632,7 @@ void handleRunningTCPQuestion(int fd, boost::any& var) } conn.bytesread+=bytes; if(conn.bytesread==conn.qlen) { - // conn.state=TCPConnection::DONE; // this makes us immune from timeouts, from now on *we* are responsible - conn.state=TCPConnection::BYTE0; // *wrong* - yes, we want to listen for a new question already, but we shouldn't timeout etc + conn.state=TCPConnection::DONE; // this makes us immune from timeouts, from now on *we* are responsible DNSComboWriter* dc=0; try { dc=new DNSComboWriter(conn.data, conn.qlen, g_now); @@ -1313,15 +1299,16 @@ int main(int argc, char **argv) MT->makeThread(houseKeeping,0); } - if(!(counter%1)) { + if(!(counter%11)) { typedef vector > expired_t; expired_t expired=g_fdm->getTimeouts(g_now); for(expired_t::iterator i=expired.begin() ; i != expired.end(); ++i) { TCPConnection conn=any_cast(i->second); - g_fdm->removeReadFD(i->first); - cerr<<"Closed connection with our client "<first<<"\n"; - conn.closeAndCleanup(); + if(conn.state != TCPConnection::DONE) { + g_fdm->removeReadFD(i->first); + conn.closeAndCleanup(); + } } }