This is an automated email from the ASF dual-hosted git repository.

cmcfarlen pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 427c1198b38fbfb34eda520642b66ca8430133cd
Author: Damian Meden <[email protected]>
AuthorDate: Wed Jul 3 18:17:01 2024 +0200

    H3: Make sure we remove streams when needed. (#11490)
    
    * H3: Make sure we remove streams when needed.
    Streams weren’t deleted when needed. Stream list was increasing
    in size as items were never removed from it, generating a very
    large list and making finding items slow as we needed to walk
    over a large list.
    This fixes the logic to check if the stream is ready to be
    removed if so, then the stream is correctly removed from the list.
    
    (cherry picked from commit 97cb0aa0c0111ccc52234bb81b10c4dd7fc7c7af)
---
 include/iocore/net/quic/QUICStreamManager.h |  3 ++-
 src/iocore/net/QUICNetVConnection.cc        |  8 ++++----
 src/iocore/net/quic/QUICStreamManager.cc    | 21 ++++++++++++++++-----
 src/iocore/net/quic/QUICStreamVCAdapter.cc  |  4 ++--
 4 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/include/iocore/net/quic/QUICStreamManager.h 
b/include/iocore/net/quic/QUICStreamManager.h
index e0fff97974..78985a7d3c 100644
--- a/include/iocore/net/quic/QUICStreamManager.h
+++ b/include/iocore/net/quic/QUICStreamManager.h
@@ -46,7 +46,8 @@ public:
   uint32_t    stream_count() const;
   QUICStream *find_stream(QUICStreamId stream_id);
 
-  QUICConnectionErrorUPtr create_stream(QUICStreamId stream_id);
+  QUICStream *create_stream(QUICStreamId stream_id, QUICConnectionError &err);
+
   QUICConnectionErrorUPtr create_uni_stream(QUICStreamId new_stream_id);
   QUICConnectionErrorUPtr create_bidi_stream(QUICStreamId new_stream_id);
   QUICConnectionErrorUPtr delete_stream(QUICStreamId new_stream_id);
diff --git a/src/iocore/net/QUICNetVConnection.cc 
b/src/iocore/net/QUICNetVConnection.cc
index 777c8b7c8d..78aa76f376 100644
--- a/src/iocore/net/QUICNetVConnection.cc
+++ b/src/iocore/net/QUICNetVConnection.cc
@@ -611,8 +611,8 @@ QUICNetVConnection::_handle_read_ready()
     QUICConVDebug("stream %" PRIu64 " is readable\n", s);
     QUICStream *stream = static_cast<QUICStream 
*>(this->_stream_manager->find_stream(s));
     if (stream == nullptr) {
-      this->_stream_manager->create_stream(s);
-      stream = static_cast<QUICStream 
*>(this->_stream_manager->find_stream(s));
+      [[maybe_unused]] QUICConnectionError err;
+      stream = this->_stream_manager->create_stream(s, err);
     }
     stream->receive_data(this->_quiche_con);
   }
@@ -628,8 +628,8 @@ QUICNetVConnection::_handle_write_ready()
     while (quiche_stream_iter_next(writable, &s)) {
       QUICStream *stream = static_cast<QUICStream 
*>(this->_stream_manager->find_stream(s));
       if (stream == nullptr) {
-        this->_stream_manager->create_stream(s);
-        stream = static_cast<QUICStream 
*>(this->_stream_manager->find_stream(s));
+        [[maybe_unused]] QUICConnectionError err;
+        stream = this->_stream_manager->create_stream(s, err);
       }
       stream->send_data(this->_quiche_con);
     }
diff --git a/src/iocore/net/quic/QUICStreamManager.cc 
b/src/iocore/net/quic/QUICStreamManager.cc
index 63cf957dd9..6daef69d6e 100644
--- a/src/iocore/net/quic/QUICStreamManager.cc
+++ b/src/iocore/net/quic/QUICStreamManager.cc
@@ -30,7 +30,19 @@
 
 QUICStreamManager::QUICStreamManager(QUICContext *context, QUICApplicationMap 
*app_map) : _context(context), _app_map(app_map) {}
 
-QUICStreamManager::~QUICStreamManager() {}
+QUICStreamManager::~QUICStreamManager()
+{
+  // We attempt to remove any stream that's left on the list.
+  if (!stream_list.empty()) {
+    QUICStream *stream = stream_list.head;
+    while (stream) {
+      QUICStream *next = stream->link.next;
+      stream_list.remove(stream);
+      delete stream;
+      stream = next;
+    }
+  }
+}
 
 void
 QUICStreamManager::set_default_application(QUICApplication *app)
@@ -89,15 +101,15 @@ QUICStreamManager::find_stream(QUICStreamId stream_id)
   return nullptr;
 }
 
-QUICConnectionErrorUPtr
-QUICStreamManager::create_stream(QUICStreamId stream_id)
+QUICStream *
+QUICStreamManager::create_stream(QUICStreamId stream_id, QUICConnectionError 
&err)
 {
   QUICStream *stream = new QUICStream(this->_context->connection_info(), 
stream_id);
   this->stream_list.push(stream);
 
   QUICApplication *application = this->_app_map->get(stream_id);
   application->on_stream_open(*stream);
-  return nullptr;
+  return stream;
 }
 
 QUICConnectionErrorUPtr
@@ -121,7 +133,6 @@ QUICStreamManager::delete_stream(QUICStreamId stream_id)
   application->on_stream_close(*stream);
 
   stream_list.remove(stream);
-
   delete stream;
 
   return nullptr;
diff --git a/src/iocore/net/quic/QUICStreamVCAdapter.cc 
b/src/iocore/net/quic/QUICStreamVCAdapter.cc
index 377b7ef5f0..ca7bd94063 100644
--- a/src/iocore/net/quic/QUICStreamVCAdapter.cc
+++ b/src/iocore/net/quic/QUICStreamVCAdapter.cc
@@ -331,13 +331,13 @@ QUICStreamVCAdapter::reenable(VIO * /* vio ATS_UNUSED */)
 bool
 QUICStreamVCAdapter::is_readable()
 {
-  return this->stream().direction() != QUICStreamDirection::SEND && 
_read_vio.nbytes == _read_vio.ndone;
+  return this->stream().direction() != QUICStreamDirection::SEND && 
_read_vio.nbytes != _read_vio.ndone;
 }
 
 bool
 QUICStreamVCAdapter::is_writable()
 {
-  return this->stream().direction() != QUICStreamDirection::RECEIVE && 
_write_vio.nbytes != -1;
+  return this->stream().direction() != QUICStreamDirection::RECEIVE && 
_write_vio.nbytes != _read_vio.ndone;
 }
 
 int

Reply via email to