Don't Prematurely Discard TLS State on Server
@@ -1227,6 +1227,10 @@ QuicCryptoProcessTlsCompletion(
QUIC_TEL_ASSERT(!Connection->State.Connected);
QuicTraceEvent(ConnHandshakeComplete, Connection);
+ InterlockedDecrement(&Connection->Paths[0].Binding->HandshakeConnections);
+ InterlockedExchangeAdd64(
+ (int64_t*)&MsQuicLib.CurrentHandshakeMemoryUsage,
+ -1 * (int64_t)QUIC_CONN_HANDSHAKE_MEMORY_USAGE);
//
// We should have the 1-RTT keys by connection complete time.
@@ -1234,15 +1238,6 @@ QuicCryptoProcessTlsCompletion(
QUIC_TEL_ASSERT(Crypto->TlsState.ReadKeys[QUIC_PACKET_KEY_1_RTT] != NULL);
QUIC_TEL_ASSERT(Crypto->TlsState.WriteKeys[QUIC_PACKET_KEY_1_RTT] != NULL);
- //
- // Only mark the handshake as complete on success.
- //
- Connection->State.Connected = TRUE;
- InterlockedDecrement(&Connection->Paths[0].Binding->HandshakeConnections);
- InterlockedExchangeAdd64(
- (int64_t*)&MsQuicLib.CurrentHandshakeMemoryUsage,
- -1 * (int64_t)QUIC_CONN_HANDSHAKE_MEMORY_USAGE);
-
if (QuicConnIsServer(Connection)) {
//
// Handshake is confirmed on the server side as soon as it completes.
@@ -1252,6 +1247,13 @@ QuicCryptoProcessTlsCompletion(
QuicCryptoHandshakeConfirmed(&Connection->Crypto);
}
+ //
+ // Only set the connected flag after we do the confirmation code path
+ // above so that TLS state isn't prematurely destroyed (before the
+ // CONNECTED event is indicated to the app).
+ //
+ Connection->State.Connected = TRUE;
+
(void)QuicConnGenerateNewSourceCid(Connection, FALSE);
if (!QuicConnIsServer(Connection) &&
