Skip to content

Commit 5e7120c

Browse files
authored
[Release/8.0-staging] Fix issue where the IPC server can fully consume a CPU core and prevent incoming connections (#102530)
* 8 fix for ipc * Update ds-ipc-pal-namedpipe.c
1 parent bfaf24e commit 5e7120c

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/native/eventpipe/ds-ipc-pal-namedpipe.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,27 @@ ds_ipc_free (DiagnosticsIpc *ipc)
173173
ep_rt_object_free (ipc);
174174
}
175175

176+
void
177+
ds_ipc_reset (DiagnosticsIpc *ipc)
178+
{
179+
if (!ipc)
180+
return;
181+
182+
if (ipc->pipe != INVALID_HANDLE_VALUE) {
183+
DisconnectNamedPipe (ipc->pipe);
184+
CloseHandle (ipc->pipe);
185+
ipc->pipe = INVALID_HANDLE_VALUE;
186+
}
187+
188+
if (ipc->overlap.hEvent != INVALID_HANDLE_VALUE) {
189+
CloseHandle (ipc->overlap.hEvent);
190+
}
191+
192+
memset(&ipc->overlap, 0, sizeof(OVERLAPPED)); // clear the overlapped objects state
193+
ipc->overlap.hEvent = INVALID_HANDLE_VALUE;
194+
ipc->is_listening = false;
195+
}
196+
176197
int32_t
177198
ds_ipc_poll (
178199
DiagnosticsIpcPollHandle *poll_handles_data,
@@ -192,6 +213,10 @@ ds_ipc_poll (
192213
// SERVER
193214
EP_ASSERT (poll_handles_data [i].ipc->mode == DS_IPC_CONNECTION_MODE_LISTEN);
194215
handles [i] = poll_handles_data [i].ipc->overlap.hEvent;
216+
if (handles [i] == INVALID_HANDLE_VALUE) {
217+
// Invalid handle, wait will fail. Signal error
218+
poll_handles_data [i].events = DS_IPC_POLL_EVENTS_ERR;
219+
}
195220
} else {
196221
// CLIENT
197222
bool success = true;

src/native/eventpipe/ds-ipc-pal-socket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,11 @@ ds_ipc_free (DiagnosticsIpc *ipc)
10641064
ep_rt_object_free (ipc);
10651065
}
10661066

1067+
void
1068+
ds_ipc_reset (DiagnosticsIpc *ipc)
1069+
{
1070+
}
1071+
10671072
int32_t
10681073
ds_ipc_poll (
10691074
DiagnosticsIpcPollHandle *poll_handles_data,

src/native/eventpipe/ds-ipc-pal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ ds_ipc_alloc (
3535
void
3636
ds_ipc_free (DiagnosticsIpc *ipc);
3737

38+
void
39+
ds_ipc_reset (DiagnosticsIpc *ipc);
40+
3841
// Poll
3942
// Parameters:
4043
// - IpcPollHandle * poll_handles_data: Array of IpcPollHandles to poll

src/native/eventpipe/ds-ipc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,11 @@ listen_port_reset (
839839
ds_ipc_error_callback_func callback)
840840
{
841841
EP_ASSERT (object != NULL);
842-
return;
842+
#ifdef _WIN32
843+
DiagnosticsListenPort *listen_port = (DiagnosticsListenPort *)object;
844+
ds_ipc_reset (listen_port->port.ipc);
845+
ds_ipc_listen (listen_port->port.ipc, callback);
846+
#endif // _WIN32
843847
}
844848

845849
static DiagnosticsPortVtable listen_port_vtable = {

0 commit comments

Comments
 (0)