]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Cap the amount of data buffered toward a DoH server 17215/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 2 Apr 2026 13:24:06 +0000 (15:24 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 2 Apr 2026 13:24:06 +0000 (15:24 +0200)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist-nghttp2.cc

index 5fde5345b76fc0e2e018dc4fb5adb21ab0e06cfb..67692175ef5b160a30ddb4a0215099b23b0f71de 100644 (file)
@@ -82,6 +82,10 @@ public:
   }
 
 private:
+  /* how many bytes we are willing to keep in a buffer waiting for the socket to become writable
+     again, until we stop accepting new queries */
+  static constexpr size_t s_maxBufferedBytes = 65536U;
+
   static ssize_t send_callback(nghttp2_session* session, const uint8_t* data, size_t length, int flags, void* user_data);
   static int on_frame_recv_callback(nghttp2_session* session, const nghttp2_frame* frame, void* user_data);
   static int on_data_chunk_recv_callback(nghttp2_session* session, uint8_t flags, StreamID stream_id, const uint8_t* data, size_t len, void* user_data);
@@ -239,6 +243,13 @@ bool DoHConnectionToBackend::reachedMaxConcurrentQueries() const
   if (nghttp2_session_get_remote_settings(d_session.get(), NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS) <= getConcurrentStreamsCount()) {
     return true;
   }
+
+  /* somehow we already have a lot of data queued that we have not been able to
+     write to the outgoing socket, do not accept new queries just yet */
+  if (d_out.size() >= s_maxBufferedBytes) {
+    return true;
+  }
+
   return false;
 }