cudaipcsink: Fix deadlock on stop

Manually close connection if client does not hold any shared memory
on stop.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5747>
This commit is contained in:
Seungha Yang 2023-12-01 21:38:17 +09:00 committed by GStreamer Marge Bot
parent ed5987efd4
commit 012222bcb3
4 changed files with 30 additions and 2 deletions

View file

@ -630,14 +630,28 @@ gst_cuda_ipc_server_on_idle (GstCudaIpcServer * server)
GST_DEBUG_OBJECT (server, "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 (server, "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 ()) {
conn->CloseConn ();
num_closed++;
}
}
/* *INDENT-ON* */
if (priv->conn_map.size () == num_closed) {
GST_DEBUG_OBJECT (server, "All connections were closed");
klass->terminate (server);
}
return;
}

View file

@ -150,6 +150,8 @@ struct GstCudaIpcServerConn : public OVERLAPPED
gst_clear_caps (&caps);
}
virtual void CloseConn () = 0;
GstCudaIpcServer *server;
GstCudaContext *context = nullptr;

View file

@ -47,8 +47,14 @@ struct GstCudaIpcServerConnUnix : public GstCudaIpcServerConn
g_clear_object (&socket_conn);
}
void CloseConn ()
{
if (socket_conn)
g_io_stream_close (G_IO_STREAM (socket_conn), nullptr, nullptr);
}
/* Holds ref */
GSocketConnection *socket_conn;
GSocketConnection *socket_conn = nullptr;
/* Owned by socket_conn */
GInputStream *istream;

View file

@ -41,15 +41,21 @@ struct GstCudaIpcServerConnWin32 : public GstCudaIpcServerConn
}
virtual ~GstCudaIpcServerConnWin32 ()
{
CloseConn ();
}
void CloseConn ()
{
if (pipe != INVALID_HANDLE_VALUE) {
CancelIo (pipe);
DisconnectNamedPipe (pipe);
CloseHandle (pipe);
pipe = INVALID_HANDLE_VALUE;
}
}
HANDLE pipe;
HANDLE pipe = INVALID_HANDLE_VALUE;
};
struct GstCudaIpcServerWin32Private