Fix opening the debug tap (#11445)
It's possible that we're about to be started, _before_ our paired connection is started. Both will get Start()'ed when their owning TermControl is finally laid out. However, if we're started first, then we'll immediately start printing to the other control as well, which might not have initialized yet. If we do that, we'll explode. Instead, wait here until the other connection is started too, before actually starting the connection to the client app. This will ensure both controls are initialized before the client app is. Fixes #11282 Tested: Opened about 100 debug taps. They all worked. :shipit:
This commit is contained in:
parent
c727762602
commit
bd8bfa13bb
|
@ -21,8 +21,22 @@ namespace winrt::Microsoft::TerminalApp::implementation
|
|||
}
|
||||
void Initialize(const Windows::Foundation::Collections::ValueSet& /*settings*/) {}
|
||||
~DebugInputTapConnection() = default;
|
||||
void Start()
|
||||
winrt::fire_and_forget Start()
|
||||
{
|
||||
// GH#11282: It's possible that we're about to be started, _before_
|
||||
// our paired connection is started. Both will get Start()'ed when
|
||||
// their owning TermControl is finally laid out. However, if we're
|
||||
// started first, then we'll immediately start printing to the other
|
||||
// control as well, which might not have initialized yet. If we do
|
||||
// that, we'll explode.
|
||||
//
|
||||
// Instead, wait here until the other connection is started too,
|
||||
// before actually starting the connection to the client app. This
|
||||
// will ensure both controls are initialized before the client app
|
||||
// is.
|
||||
co_await winrt::resume_background();
|
||||
_pairedTap->_start.wait();
|
||||
|
||||
_wrappedConnection.Start();
|
||||
}
|
||||
void WriteInput(hstring const& data)
|
||||
|
@ -59,6 +73,9 @@ namespace winrt::Microsoft::TerminalApp::implementation
|
|||
void DebugTapConnection::Start()
|
||||
{
|
||||
// presume the wrapped connection is started.
|
||||
|
||||
// This is explained in the comment for GH#11282 above.
|
||||
_start.count_down();
|
||||
}
|
||||
|
||||
void DebugTapConnection::WriteInput(hstring const& data)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <winrt/Microsoft.Terminal.TerminalConnection.h>
|
||||
#include "../../inc/cppwinrt_utils.h"
|
||||
#include <til/latch.h>
|
||||
|
||||
namespace winrt::Microsoft::TerminalApp::implementation
|
||||
{
|
||||
|
@ -36,6 +37,8 @@ namespace winrt::Microsoft::TerminalApp::implementation
|
|||
winrt::weak_ref<Microsoft::Terminal::TerminalConnection::ITerminalConnection> _wrappedConnection;
|
||||
winrt::weak_ref<Microsoft::Terminal::TerminalConnection::ITerminalConnection> _inputSide;
|
||||
|
||||
til::latch _start{ 1 };
|
||||
|
||||
friend class DebugInputTapConnection;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1025,7 +1025,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
|||
|
||||
TerminalConnection::ConnectionState ControlCore::ConnectionState() const
|
||||
{
|
||||
return _connection.State();
|
||||
return _connection ? _connection.State() : TerminalConnection::ConnectionState::Closed;
|
||||
}
|
||||
|
||||
hstring ControlCore::Title()
|
||||
|
|
Loading…
Reference in New Issue