Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit c4df438

Browse files
authored
Clean up diagnosticserver socket on unexpected shutdown (#25976) (#26190)
* Clean up diagnosticserver socket/pipe on shutdown * Refactor dbg transport pipe cleanup to be registered as signal handler from the vm side * cleanup dead code * Remove more dead code and fix windows builds * Moving some ifdefs around
1 parent cca2f13 commit c4df438

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

src/debug/ee/debugger.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -890,15 +890,6 @@ ShutdownTransport()
890890
g_pDbgTransport = NULL;
891891
}
892892
}
893-
894-
void
895-
AbortTransport()
896-
{
897-
if (g_pDbgTransport != NULL)
898-
{
899-
g_pDbgTransport->AbortConnection();
900-
}
901-
}
902893
#endif // FEATURE_DBGIPC_TRANSPORT_VM
903894

904895

@@ -1895,6 +1886,16 @@ void NotifyDebuggerOfStartup()
18951886

18961887
#endif // !FEATURE_PAL
18971888

1889+
void Debugger::CleanupTransportSocket(void)
1890+
{
1891+
#if defined(FEATURE_PAL) && defined(FEATURE_DBGIPC_TRANSPORT_VM)
1892+
if (g_pDbgTransport != NULL)
1893+
{
1894+
g_pDbgTransport->AbortConnection();
1895+
}
1896+
#endif // FEATURE_PAL && FEATURE_DBGIPC_TRANSPORT_VM
1897+
}
1898+
18981899
//---------------------------------------------------------------------------------------
18991900
//
19001901
// Initialize Left-Side debugger object
@@ -2047,9 +2048,6 @@ HRESULT Debugger::Startup(void)
20472048
ShutdownTransport();
20482049
ThrowHR(hr);
20492050
}
2050-
#ifdef FEATURE_PAL
2051-
PAL_SetShutdownCallback(AbortTransport);
2052-
#endif // FEATURE_PAL
20532051
#endif // FEATURE_DBGIPC_TRANSPORT_VM
20542052

20552053
RaiseStartupNotification();

src/debug/ee/debugger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,8 @@ class Debugger : public DebugInterface
18521852

18531853
HRESULT StartupPhase2(Thread * pThread);
18541854

1855+
void CleanupTransportSocket();
1856+
18551857
void InitializeLazyDataIfNecessary();
18561858

18571859
void LazyInit(); // will throw

src/vm/ceemain.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,31 @@ do { \
596596
#define IfFailGoLog(EXPR) IfFailGotoLog(EXPR, ErrExit)
597597
#endif
598598

599+
600+
#ifndef CROSSGEN_COMPILE
601+
#ifdef FEATURE_PAL
602+
void EESocketCleanupHelper()
603+
{
604+
CONTRACTL
605+
{
606+
GC_NOTRIGGER;
607+
MODE_ANY;
608+
} CONTRACTL_END;
609+
610+
// Close the debugger transport socket first
611+
if (g_pDebugInterface != NULL)
612+
{
613+
g_pDebugInterface->CleanupTransportSocket();
614+
}
615+
616+
// Close the diagnostic server socket.
617+
#ifdef FEATURE_PERFTRACING
618+
DiagnosticServer::Shutdown();
619+
#endif // FEATURE_PERFTRACING
620+
}
621+
#endif // FEATURE_PAL
622+
#endif // CROSSGEN_COMPILE
623+
599624
void EEStartupHelper(COINITIEE fFlags)
600625
{
601626
CONTRACTL
@@ -653,8 +678,13 @@ void EEStartupHelper(COINITIEE fFlags)
653678
#ifdef FEATURE_PERFTRACING
654679
// Initialize the event pipe.
655680
EventPipe::Initialize();
681+
656682
#endif // FEATURE_PERFTRACING
657683

684+
#ifdef FEATURE_PAL
685+
PAL_SetShutdownCallback(EESocketCleanupHelper);
686+
#endif // FEATURE_PAL
687+
658688
#ifdef FEATURE_GDBJIT
659689
// Initialize gdbjit
660690
NotifyGdb::Initialize();

src/vm/dbginterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ class DebugInterface
399399
virtual LONG FirstChanceSuspendHijackWorker(PCONTEXT pContext, PEXCEPTION_RECORD pExceptionRecord) = 0;
400400
#endif
401401

402+
// Helper method for cleaning up transport socket
403+
virtual void CleanupTransportSocket(void) = 0;
404+
402405
#endif // #ifndef DACCESS_COMPILE
403406

404407
#ifdef DACCESS_COMPILE

0 commit comments

Comments
 (0)