Skip to content

Commit

Permalink
feat: close listeners in registration rundown (#3823)
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan authored Aug 28, 2023
1 parent 6935fdf commit f91ccc2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/core/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,26 @@ MsQuicListenerOpen(
QuicSiloAddRef(Listener->Silo);
#endif

BOOLEAN RegistrationShuttingDown;

BOOLEAN Result = CxPlatRundownAcquire(&Registration->Rundown);
CXPLAT_DBG_ASSERT(Result); UNREFERENCED_PARAMETER(Result);

CxPlatDispatchLockAcquire(&Registration->ConnectionLock);
RegistrationShuttingDown = Registration->ShuttingDown;
if (!RegistrationShuttingDown) {
CxPlatListInsertTail(&Registration->Listeners, &Listener->RegistrationLink);
}
CxPlatDispatchLockRelease(&Registration->ConnectionLock);

if (RegistrationShuttingDown) {
CxPlatRundownRelease(&Registration->Rundown);
CxPlatEventUninitialize(Listener->StopEvent);
CXPLAT_FREE(Listener, QUIC_POOL_LISTENER);
Listener = NULL;
Status = QUIC_STATUS_INVALID_STATE;
goto Error;
}
QuicTraceEvent(
ListenerCreated,
"[list][%p] Created, Registration=%p",
Expand Down Expand Up @@ -117,6 +134,12 @@ QuicListenerFree(
QuicSiloRelease(Listener->Silo);
#endif

CxPlatDispatchLockAcquire(&Listener->Registration->ConnectionLock);
if (!Listener->Registration->ShuttingDown) {
CxPlatListEntryRemove(&Listener->RegistrationLink);
}
CxPlatDispatchLockRelease(&Listener->Registration->ConnectionLock);

CxPlatRefUninitialize(&Listener->RefCount);
CxPlatEventUninitialize(Listener->StopEvent);
CXPLAT_DBG_ASSERT(Listener->AlpnList == NULL);
Expand Down
5 changes: 5 additions & 0 deletions src/core/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ typedef struct QUIC_LISTENER {
//
QUIC_REGISTRATION* Registration;

//
// Link into the registrations's list of listeners.
//
CXPLAT_LIST_ENTRY RegistrationLink;

#ifdef QUIC_SILO
//
// The silo.
Expand Down
9 changes: 9 additions & 0 deletions src/core/registration.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ MsQuicRegistrationOpen(
CxPlatListInitializeHead(&Registration->Configurations);
CxPlatDispatchLockInitialize(&Registration->ConnectionLock);
CxPlatListInitializeHead(&Registration->Connections);
CxPlatListInitializeHead(&Registration->Listeners);
CxPlatRundownInitialize(&Registration->Rundown);
Registration->AppNameLength = (uint8_t)(AppNameLength + 1);
if (AppNameLength != 0) {
Expand Down Expand Up @@ -248,6 +249,14 @@ MsQuicRegistrationShutdown(
}

CxPlatDispatchLockRelease(&Registration->ConnectionLock);

Entry = Registration->Listeners.Flink;
while (Entry != &Registration->Listeners) {
QUIC_LISTENER* Listener =
CXPLAT_CONTAINING_RECORD(Entry, QUIC_LISTENER, RegistrationLink);
Entry = Entry->Flink;
MsQuicListenerStop((HQUIC)Listener);
}
}

Exit:
Expand Down
7 changes: 6 additions & 1 deletion src/core/registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef struct QUIC_REGISTRATION {
CXPLAT_LIST_ENTRY Configurations;

//
// Protects access to the Connections list.
// Protects access to the Connections list and the Listeners list.
//
CXPLAT_DISPATCH_LOCK ConnectionLock;

Expand All @@ -90,6 +90,11 @@ typedef struct QUIC_REGISTRATION {
//
CXPLAT_LIST_ENTRY Connections;

//
// List of all Listeners for this registration.
//
CXPLAT_LIST_ENTRY Listeners;

//
// Rundown for all child objects.
//
Expand Down

0 comments on commit f91ccc2

Please sign in to comment.