From 5ed736b053eb9d04ecd1a6f2f375cce7fcefe4e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 7 Feb 2024 18:56:19 +0100 Subject: Http/2: fix active streams counting We were looking at all active streams, but that also includes promised streams. By the RFC the limitation that our peer specifies only applies to the number of streams _we_ create, not the total amount of active streams. More importantly, for the qhttp2protocolhandler it could mean that we could end up having a few promised streams push the active stream count over the limit, which could lead us to start more streams than intended (then bounded by the number of queued requests). The worst case in this scenario is that a **non-compliant** server doesn't track how many connections we open and the user has queued a ton of requests, so we open a ton of streams. But on the upside: server-push is not widely used. Pick-to: 6.7 Change-Id: I2a533472eb9127fd176bb99e9db0518f05c3fffe Reviewed-by: Timur Pocheptsov Reviewed-by: Edward Welbourne Reviewed-by: Alexey Edelev --- src/network/access/qhttp2protocolhandler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/network/access/qhttp2protocolhandler.cpp') diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp index b2b3676fd7..376f7251ff 100644 --- a/src/network/access/qhttp2protocolhandler.cpp +++ b/src/network/access/qhttp2protocolhandler.cpp @@ -326,7 +326,10 @@ bool QHttp2ProtocolHandler::sendRequest() initReplyFromPushPromise(message, key); } - const qint64 streamsToUse = qBound(0, qint64(maxConcurrentStreams) - activeStreams.size(), + const auto isClientSide = [](const auto &pair) -> bool { return (pair.first & 1) == 1; }; + const auto activeClientSideStreams = std::count_if( + activeStreams.constKeyValueBegin(), activeStreams.constKeyValueEnd(), isClientSide); + const qint64 streamsToUse = qBound(0, qint64(maxConcurrentStreams) - activeClientSideStreams, requests.size()); auto it = requests.begin(); for (qint64 i = 0; i < streamsToUse; ++i) { -- cgit v1.2.3