From 5ac0c50caedaab3ceb06fed865b1371b005b5475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 28 Jun 2024 13:32:43 +0200 Subject: [PATCH] Http2: Clean out streams as they get deleted Instead of keeping the empty QPointer in the hash forever let's try to keep the hash lean as to not punish iteration over it as the streams are being created and deleted. Task-number: QTBUG-126772 Change-Id: Id7afa684a19e6a16726e5bda5debdd2f2bbe86ab Reviewed-by: Dennis Oberst (cherry picked from commit 94e8bb96304fd2ea2ddfdf2499f4024131a16a8a) Reviewed-by: Qt Cherry-pick Bot --- src/network/access/qhttp2connection.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/network/access/qhttp2connection.cpp b/src/network/access/qhttp2connection.cpp index 02334e14c56..f0d3c50956c 100644 --- a/src/network/access/qhttp2connection.cpp +++ b/src/network/access/qhttp2connection.cpp @@ -41,7 +41,23 @@ QHttp2Stream::QHttp2Stream(QHttp2Connection *connection, quint32 streamID) noexc qCDebug(qHttp2ConnectionLog, "[%p] new stream %u", connection, streamID); } -QHttp2Stream::~QHttp2Stream() noexcept = default; +QHttp2Stream::~QHttp2Stream() noexcept { + if (auto *connection = getConnection()) { + if (m_state == State::Open || m_state == State::HalfClosedRemote) { + qCDebug(qHttp2ConnectionLog, "[%p] stream %u, destroyed while still open", connection, + m_streamID); + // Check if we can still send data, then send RST_STREAM: + if (connection->getSocket()) { + if (isUploadingDATA()) + sendRST_STREAM(CANCEL); + else + sendRST_STREAM(HTTP2_NO_ERROR); + } + } + + connection->m_streams.remove(streamID()); + } +} /*! \fn quint32 QHttp2Stream::streamID() const noexcept @@ -847,6 +863,8 @@ QHttp2Connection::createStreamInternal() QHttp2Stream *QHttp2Connection::createStreamInternal_impl(quint32 streamID) { + Q_ASSERT(streamID > m_lastIncomingStreamID || streamID >= m_nextStreamID); + qsizetype numStreams = m_streams.size(); QPointer &stream = m_streams[streamID]; if (numStreams == m_streams.size()) // stream already existed