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 <dennis.oberst@qt.io>
(cherry picked from commit 94e8bb96304fd2ea2ddfdf2499f4024131a16a8a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Mårten Nordheim 2024-06-28 13:32:43 +02:00 committed by Qt Cherry-pick Bot
parent 987b215f08
commit 5ac0c50cae

View File

@ -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<QHttp2Stream> &stream = m_streams[streamID];
if (numStreams == m_streams.size()) // stream already existed