From 183a8956f699e1967d4cb4712184d0dbc395a0e5 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Thu, 16 May 2024 00:03:28 +0200 Subject: [PATCH] Fix lock warning during ReturnResponse (#17266) As reported here: https://github.com/microsoft/terminal/pull/16224#discussion_r1594849244 The underlying `WriteFile` call may block indefinitely and we shouldn't hold the terminal lock during that period. --- src/cascadia/TerminalCore/TerminalApi.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index 42f1c903c33..9b85b18d5ff 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -22,8 +22,9 @@ TRACELOGGING_DEFINE_PROVIDER(g_hCTerminalCoreProvider, void Terminal::ReturnResponse(const std::wstring_view response) { - if (_pfnWriteInput) + if (_pfnWriteInput && !response.empty()) { + const auto suspension = _readWriteLock.suspend(); _pfnWriteInput(response); } }