Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,7 @@ _site
APKBUILD

# Temporary package download folder by validation script
msquic-packages/
msquic-packages/
# CodeQL build artifacts
_codeql_build_dir/
_codeql_detected_source_root
3 changes: 2 additions & 1 deletion src/core/cubic.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ CubicCongestionControlGetNetworkStatistics(
NetworkStatistics->IdealBytes = Connection->SendBuffer.IdealBytes;
NetworkStatistics->SmoothedRTT = Path->SmoothedRtt;
NetworkStatistics->CongestionWindow = Cubic->CongestionWindow;
NetworkStatistics->Bandwidth = Cubic->CongestionWindow / Path->SmoothedRtt;
NetworkStatistics->Bandwidth =
Path->SmoothedRtt == 0 ? 0 : Cubic->CongestionWindow / Path->SmoothedRtt;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
Expand Down
30 changes: 30 additions & 0 deletions src/core/unittest/CubicTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,33 @@ TEST(CubicTest, HyStart_StateTransitions)
Cubic->HyStartState <= HYSTART_DONE);
ASSERT_GE(Cubic->CWndSlowStartGrowthDivisor, 1u);
}

//
// Test 18: GetNetworkStatistics - Zero RTT Graceful Handling
// Scenario: Verifies that GetNetworkStatistics does not divide by zero when
// SmoothedRtt is 0 (before the first RTT sample is received). It should
// return Bandwidth=0 instead of crashing.
//
TEST(CubicTest, GetNetworkStatistics_ZeroRtt)
{
QUIC_CONNECTION Connection;
QUIC_SETTINGS_INTERNAL Settings{};
Settings.InitialWindowPackets = 10;
Settings.SendIdleTimeoutMs = 1000;

InitializeMockConnection(Connection, 1280);
// SmoothedRtt is 0 by default (no RTT sample received yet)

CubicCongestionControlInitialize(&Connection.CongestionControl, &Settings);

QUIC_NETWORK_STATISTICS NetworkStats;
CxPlatZeroMemory(&NetworkStats, sizeof(NetworkStats));

Connection.CongestionControl.QuicCongestionControlGetNetworkStatistics(
&Connection,
&Connection.CongestionControl,
&NetworkStats);

// Bandwidth should be 0 when SmoothedRtt is 0 (graceful degradation)
ASSERT_EQ(NetworkStats.Bandwidth, 0u);
}