From ed5987efd4262fe3c4d5f8024a7fce0abcd906e4 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 1 Dec 2023 21:15:00 +0900 Subject: [PATCH] d3d11ipcsink: Fix deadlock on stop Manually close connection if client does not hold any shared memory on stop. Part-of: --- .../sys/d3d11/gstd3d11ipcserver.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11ipcserver.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11ipcserver.cpp index 3e49e1c912..e1c51dd438 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11ipcserver.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11ipcserver.cpp @@ -521,14 +521,34 @@ gst_d3d11_ipc_server_on_idle (GstD3D11IpcServer * self) GST_DEBUG_OBJECT (self, "Have %" G_GSIZE_FORMAT " alive connections", priv->conn_map.size()); + + size_t num_closed = 0; for (auto it : priv->conn_map) { auto conn = it.second; GST_DEBUG_OBJECT (self, "conn-id %u" " peer handle size %" G_GSIZE_FORMAT, conn->id, conn->peer_handles.size ()); + + /* Cannot erase conn since it's still referenced. + * Manually close connection */ + if (conn->peer_handles.empty ()) { + if (conn->pipe != INVALID_HANDLE_VALUE) { + CancelIo (conn->pipe); + DisconnectNamedPipe (conn->pipe); + CloseHandle (conn->pipe); + conn->pipe = INVALID_HANDLE_VALUE; + } + + num_closed++; + } } /* *INDENT-ON* */ + if (priv->conn_map.size () == num_closed) { + GST_DEBUG_OBJECT (self, "All connections were closed"); + SetEvent (priv->cancellable); + } + return; }