From 5622f230a8291d8be69b99eb279c2ac915580765 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett (MSFT)" Date: Wed, 8 Apr 2020 13:55:20 -0700 Subject: [PATCH] Control: Start the connection outside of lock (#5286) When the connection printed text immediately, synchronously, as part of Start() it would cause terminal to deadlock. We should start the connection outside of lock. The ConptyConnection would do this when it failed to launch something (trivial repro: `wt -- xyz`). The TelnetConnection would do this all the time, because local loopback telnet is fast and easy. --- src/cascadia/TerminalControl/TermControl.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 2ce794eecc1..bfa107318d8 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -632,11 +632,15 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // becomes a no-op. this->Focus(FocusState::Programmatic); - _connection.Start(); _initializedTerminal = true; } // scope for TerminalLock - // call this event dispatcher outside of lock + // Start the connection outside of lock, because it could + // start writing output immediately. + _connection.Start(); + + // Likewise, run the event handlers outside of lock (they could + // be reentrant) _InitializedHandlers(*this, nullptr); return true; }