From 5a19a7c8e8e8734d1f42536547b080f4ee61b3aa Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 25 Nov 2020 12:31:20 +0000 Subject: [PATCH] IPC: Fix potential deadlock in win32 NamedPipe implementation We use a manual-reset event rather than an auto-reset event to cancel IO on the pipe. This avoids unlucky cases where new IO would start just after signalling the event and would block indefinitely while waiting on the newly-unsignalled event. --- modules/juce_core/native/juce_win32_Files.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/juce_core/native/juce_win32_Files.cpp b/modules/juce_core/native/juce_win32_Files.cpp index be764d9b8d..9547df8c24 100644 --- a/modules/juce_core/native/juce_win32_Files.cpp +++ b/modules/juce_core/native/juce_win32_Files.cpp @@ -975,7 +975,7 @@ public: Pimpl (const String& pipeName, const bool createPipe, bool mustNotExist) : filename ("\\\\.\\pipe\\" + File::createLegalFileName (pipeName)), pipeH (INVALID_HANDLE_VALUE), - cancelEvent (CreateEvent (nullptr, FALSE, FALSE, nullptr)), + cancelEvent (CreateEvent (nullptr, TRUE, FALSE, nullptr)), connected (false), ownsPipe (createPipe), shouldStop (false) { if (createPipe) @@ -1157,7 +1157,7 @@ private: } HANDLE handles[] = { over.over.hEvent, cancelEvent }; - DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE, + DWORD waitResult = WaitForMultipleObjects (numElementsInArray (handles), handles, FALSE, timeOutMilliseconds >= 0 ? (DWORD) timeOutMilliseconds : INFINITE);