From ee8e8da614829724caf78d04b2e95e8d9cd6800f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 19 Nov 2021 23:36:13 +0100 Subject: [PATCH] Stop auto-connect thread before terminating ctrl surfaces This works around a race-condition, calling d'tors from two threads concurrently. The GUI thread destroys ctrl surfaces. ~~MIDIControllable() calls ::drop_external_control() -> ::midi_forget() This unsubscribes from signals (notably MIDI::Parser events) by calling ScopedConnection::disconnect(), Connection::disconnect(). At the same time auto_connect_thread can call PortManager::clear_pending_port_deletions() which removes the MIDI port and destorys the MIDI::Parser. ~Parser() calls Connection::signal_going_away() to invalidate connected signals. This can deadlock if it is called concurrently with Connection::disconnect() on the same signal. see also https://discourse.ardour.org/t/ardour-session-close-hangs/106523/10 --- libs/ardour/session.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 2936d6468a..83664f2c03 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -614,14 +614,14 @@ Session::destroy () Port::PortSignalDrop (); /* EMIT SIGNAL */ drop_connections (); + /* stop auto dis/connecting */ + auto_connect_thread_terminate (); + /* shutdown control surface protocols while we still have ports * and the engine to move data to any devices. */ ControlProtocolManager::instance().drop_protocols (); - /* stop auto dis/connecting */ - auto_connect_thread_terminate (); - _engine.remove_session (); /* deregister all ports - there will be no process or any other