gfe-relnote: Do not pad server initial connection close packet. Protected by blocked gfe2_reloadable_flag_quic_enable_version_t*. PiperOrigin-RevId: 294975306 Change-Id: Iee6759502df58292cc69f634c6273bd3b5b542b7
diff --git a/quic/core/quic_connection_test.cc b/quic/core/quic_connection_test.cc index 67e2ab0..a7eac86 100644 --- a/quic/core/quic_connection_test.cc +++ b/quic/core/quic_connection_test.cc
@@ -8173,6 +8173,26 @@ ASSERT_TRUE(writer_->coalesced_packet() == nullptr); } +TEST_P(QuicConnectionTest, DoNotPadServerInitialConnectionClose) { + if (!connection_.SupportsMultiplePacketNumberSpaces()) { + return; + } + set_perspective(Perspective::IS_SERVER); + + EXPECT_CALL(visitor_, OnConnectionClosed(_, _)); + const QuicErrorCode kQuicErrorCode = QUIC_INTERNAL_ERROR; + connection_.CloseConnection( + kQuicErrorCode, "Some random error message", + ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); + + EXPECT_EQ(2u, QuicConnectionPeer::GetNumEncryptionLevels(&connection_)); + + TestConnectionCloseQuicErrorCode(kQuicErrorCode); + EXPECT_EQ(1u, writer_->connection_close_frames().size()); + EXPECT_TRUE(writer_->padding_frames().empty()); + EXPECT_EQ(ENCRYPTION_INITIAL, writer_->framer()->last_decrypted_level()); +} + // Regression test for b/63620844. TEST_P(QuicConnectionTest, FailedToWriteHandshakePacket) { SimulateNextPacketTooLarge();
diff --git a/quic/core/quic_packet_creator.cc b/quic/core/quic_packet_creator.cc index 30df1a3..aa749c6 100644 --- a/quic/core/quic_packet_creator.cc +++ b/quic/core/quic_packet_creator.cc
@@ -941,10 +941,17 @@ << "Attempt to serialize empty coalesced packet"; size_t packet_length = 0; if (coalesced.initial_packet() != nullptr) { + // Padding coalesced packet containing initial packet to full. + size_t padding_size = coalesced.max_packet_length() - coalesced.length(); + if (framer_->perspective() == Perspective::IS_SERVER && + QuicUtils::ContainsFrameType( + coalesced.initial_packet()->retransmittable_frames, + CONNECTION_CLOSE_FRAME)) { + // Do not pad server initial connection close packet. + padding_size = 0; + } size_t initial_length = ReserializeInitialPacketInCoalescedPacket( - *coalesced.initial_packet(), - /*padding_size=*/coalesced.max_packet_length() - coalesced.length(), - buffer, buffer_len); + *coalesced.initial_packet(), padding_size, buffer, buffer_len); if (initial_length == 0) { QUIC_BUG << "Failed to reserialize ENCRYPTION_INITIAL packet in " "coalesced packet";