Skip to content

Resend Close Frames #5107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 3, 2025
Merged
Changes from 6 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
6 changes: 4 additions & 2 deletions src/core/api.c
Original file line number Diff line number Diff line change
@@ -1194,7 +1194,8 @@
Oper->Type = QUIC_OPER_TYPE_API_CALL;
Oper->API_CALL.Context = &Connection->BackupApiContext;
Oper->API_CALL.Context->Type = QUIC_API_TYPE_CONN_SHUTDOWN;
Oper->API_CALL.Context->CONN_SHUTDOWN.Flags = QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT;
Oper->API_CALL.Context->CONN_SHUTDOWN.Flags =
QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT | QUIC_CONNECTION_SHUTDOWN_FLAG_STATUS;
Oper->API_CALL.Context->CONN_SHUTDOWN.ErrorCode = (QUIC_VAR_INT)QUIC_STATUS_OUT_OF_MEMORY;
Oper->API_CALL.Context->CONN_SHUTDOWN.RegistrationShutdown = FALSE;
Oper->API_CALL.Context->CONN_SHUTDOWN.TransportShutdown = TRUE;
@@ -1359,7 +1360,8 @@
Oper->Type = QUIC_OPER_TYPE_API_CALL;
Oper->API_CALL.Context = &Connection->BackupApiContext;
Oper->API_CALL.Context->Type = QUIC_API_TYPE_CONN_SHUTDOWN;
Oper->API_CALL.Context->CONN_SHUTDOWN.Flags = QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT;
Oper->API_CALL.Context->CONN_SHUTDOWN.Flags =

Check warning on line 1363 in src/core/api.c

Codecov / codecov/patch

src/core/api.c#L1363

Added line #L1363 was not covered by tests
QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT | QUIC_CONNECTION_SHUTDOWN_FLAG_STATUS;
Oper->API_CALL.Context->CONN_SHUTDOWN.ErrorCode = (QUIC_VAR_INT)QUIC_STATUS_INVALID_STATE;
Oper->API_CALL.Context->CONN_SHUTDOWN.RegistrationShutdown = FALSE;
Oper->API_CALL.Context->CONN_SHUTDOWN.TransportShutdown = TRUE;
2 changes: 2 additions & 0 deletions src/core/api.h
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@

--*/

#define QUIC_CONNECTION_SHUTDOWN_FLAG_STATUS ((QUIC_CONNECTION_SHUTDOWN_FLAGS)0x8000)

_IRQL_requires_max_(PASSIVE_LEVEL)
QUIC_STATUS
QUIC_API
3 changes: 2 additions & 1 deletion src/core/binding.c
Original file line number Diff line number Diff line change
@@ -1342,7 +1342,8 @@ QuicBindingCreateConnection(
Oper->Type = QUIC_OPER_TYPE_API_CALL;
Oper->API_CALL.Context = &NewConnection->BackupApiContext;
Oper->API_CALL.Context->Type = QUIC_API_TYPE_CONN_SHUTDOWN;
Oper->API_CALL.Context->CONN_SHUTDOWN.Flags = QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT;
Oper->API_CALL.Context->CONN_SHUTDOWN.Flags =
QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT | QUIC_CONNECTION_SHUTDOWN_FLAG_STATUS;
Oper->API_CALL.Context->CONN_SHUTDOWN.ErrorCode = (QUIC_VAR_INT)QUIC_STATUS_INTERNAL_ERROR;
Oper->API_CALL.Context->CONN_SHUTDOWN.RegistrationShutdown = FALSE;
Oper->API_CALL.Context->CONN_SHUTDOWN.TransportShutdown = TRUE;
24 changes: 24 additions & 0 deletions src/core/connection.c
Original file line number Diff line number Diff line change
@@ -432,6 +432,9 @@ QuicConnShutdown(
(!Connection->State.Started && QuicConnIsClient(Connection))) {
CloseFlags |= QUIC_CLOSE_SILENT;
}
if (Flags & QUIC_CONNECTION_SHUTDOWN_FLAG_STATUS) {
CloseFlags |= QUIC_CLOSE_QUIC_STATUS;
}

QuicConnCloseLocally(Connection, CloseFlags, ErrorCode, NULL);
}
@@ -703,6 +706,13 @@ QuicConnQueueOper(
CXPLAT_DBG_ASSERT(QuicConnIsServer(Connection));
CXPLAT_DBG_ASSERT(Connection->SourceCids.Next != NULL || CxPlatIsRandomMemoryFailureEnabled());
}
if (Oper->Type == QUIC_OPER_TYPE_API_CALL) {
if (Oper->API_CALL.Context->Type == QUIC_API_TYPE_CONN_SHUTDOWN) {
CXPLAT_DBG_ASSERT(
(Oper->API_CALL.Context->CONN_SHUTDOWN.ErrorCode <= QUIC_VAR_INT_MAX) ||
(Oper->API_CALL.Context->CONN_SHUTDOWN.Flags & QUIC_CONNECTION_SHUTDOWN_FLAG_STATUS));
}
}
#endif
if (QuicOperationEnqueue(&Connection->OperQ, Connection->Partition, Oper)) {
//
@@ -1591,6 +1601,7 @@ QuicConnTryClose(
Connection->CloseErrorCode = QUIC_ERROR_INTERNAL_ERROR;
} else {
Connection->CloseStatus = QuicErrorCodeToStatus(ErrorCode);
CXPLAT_DBG_ASSERT(ErrorCode <= QUIC_VAR_INT_MAX);
Connection->CloseErrorCode = ErrorCode;
if (QuicErrorIsProtocolError(ErrorCode)) {
QuicPerfCounterIncrement(
@@ -4411,6 +4422,19 @@ QuicConnRecvFrames(
uint16_t PayloadLength = Packet->PayloadLength;
uint64_t RecvTime = CxPlatTimeUs64();

//
// In closing state, respond to any packet with a new close frame (rate-limited).
//
if (Closed && !Connection->State.ShutdownComplete) {
if (RecvTime - Connection->LastCloseResponseTimeUs >= QUIC_CLOSING_RESPONSE_MIN_INTERVAL) {
QuicSendSetSendFlag(
&Connection->Send,
Connection->State.AppClosed ?
QUIC_CONN_SEND_FLAG_APPLICATION_CLOSE :
QUIC_CONN_SEND_FLAG_CONNECTION_CLOSE);
}
}

if (QuicConnIsClient(Connection) &&
!Connection->State.GotFirstServerResponse) {
Connection->State.GotFirstServerResponse = TRUE;
6 changes: 6 additions & 0 deletions src/core/connection.h
Original file line number Diff line number Diff line change
@@ -536,6 +536,12 @@ typedef struct QUIC_CONNECTION {
//
uint64_t EarliestExpirationTime;

//
// Timestamp (us) of when we last queued up a connection close (or
// application close) response to be sent.
//
uint64_t LastCloseResponseTimeUs;

//
// Receive packet queue.
//
6 changes: 6 additions & 0 deletions src/core/quicdef.h
Original file line number Diff line number Diff line change
@@ -318,6 +318,12 @@ CXPLAT_STATIC_ASSERT(
//
#define QUIC_DEFAULT_HANDSHAKE_IDLE_TIMEOUT 10000

//
// Minimum interval (in microseconds) between CONNECTION_CLOSE responses in
// closing state.
//
#define QUIC_CLOSING_RESPONSE_MIN_INTERVAL 5000

//
// The default value for keep alives being enabled or not.
//
1 change: 1 addition & 0 deletions src/core/send.c
Original file line number Diff line number Diff line change
@@ -307,6 +307,7 @@ QuicSendSetSendFlag(
}

if (IsCloseFrame) {
Connection->LastCloseResponseTimeUs = CxPlatTimeUs64();
QuicSendClear(Send);
}

Loading
Oops, something went wrong.