]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix timeouts on incoming DoH connections with nghttp2
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 26 Sep 2023 09:27:12 +0000 (11:27 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 3 Oct 2023 08:16:49 +0000 (10:16 +0200)
pdns/dnsdistdist/dnsdist-nghttp2-in.cc
pdns/dnsdistdist/dnsdist-nghttp2-in.hh

index 7bd9f758556cd3e1e46248c7510d522d29e30868..0302d536fee80fdb5381d533b721557877879b05 100644 (file)
@@ -951,23 +951,7 @@ int IncomingHTTP2Connection::on_stream_close_callback(nghttp2_session* session,
 {
   auto* conn = static_cast<IncomingHTTP2Connection*>(user_data);
 
-  if (error_code == 0) {
-    return 0;
-  }
-
-  auto stream = conn->d_currentStreams.find(stream_id);
-  if (stream == conn->d_currentStreams.end()) {
-    /* we don't care, then */
-    return 0;
-  }
-
-  struct timeval now
-  {
-  };
-  gettimeofday(&now, nullptr);
-  auto request = std::move(stream->second);
-  conn->d_currentStreams.erase(stream->first);
-
+  conn->d_currentStreams.erase(stream_id);
   return 0;
 }
 
@@ -1167,11 +1151,6 @@ void IncomingHTTP2Connection::handleWritableIOCallback([[maybe_unused]] int desc
   conn->writeToSocket(true);
 }
 
-bool IncomingHTTP2Connection::isIdle() const
-{
-  return getConcurrentStreamsCount() == 0;
-}
-
 void IncomingHTTP2Connection::stopIO()
 {
   d_ioState->reset();
@@ -1217,7 +1196,9 @@ void IncomingHTTP2Connection::updateIO(IOState newState, const FDMultiplexer::ca
     gettimeofday(&now, nullptr);
 
     if (newState == IOState::NeedRead) {
-      if (isIdle()) {
+      /* use the idle TTL if the handshake has been completed (and proxy protocol payload received, if any),
+         and we have processed at least one query, otherwise we use the shorter read TTL  */
+      if ((d_state == State::waitingForQuery || d_state == State::idle) && (d_queriesCount > 0 || d_currentQueriesCount)) {
         ttd = getIdleClientReadTTD(now);
       }
       else {
index a648a5027b3f15e7a3a6eac8082eaaddb3b445fe..020e1c26e312a9913d3c590a81cdba2b3f3e5337 100644 (file)
@@ -86,7 +86,6 @@ private:
   std::unique_ptr<DOHUnitInterface> getDOHUnit(uint32_t streamID) override;
 
   void stopIO();
-  bool isIdle() const;
   uint32_t getConcurrentStreamsCount() const;
   void updateIO(IOState newState, const FDMultiplexer::callbackfunc_t& callback);
   void handleIOError();