From 05382e53b1e78f402d358c5e1bb6a5d81da0d0e5 Mon Sep 17 00:00:00 2001 From: Enrico Giordani Date: Wed, 22 Jul 2015 09:34:30 +0200 Subject: [PATCH] [Fix] Workaround for VirtualProtect failing while running the cluster tests. --- src/Win32_Interop/Win32_QFork.cpp | 33 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Win32_Interop/Win32_QFork.cpp b/src/Win32_Interop/Win32_QFork.cpp index f981c354..6fd83e06 100644 --- a/src/Win32_Interop/Win32_QFork.cpp +++ b/src/Win32_Interop/Win32_QFork.cpp @@ -829,15 +829,30 @@ void CopyForkOperationData(OperationType type, LPVOID globalData, int sizeOfGlob system_category(), "BeginForkOperation: VirtualProtect failed for the fork control map"); } - if (VirtualProtect( - g_pQForkControl->heapStart, - g_pQForkControl->availableBlocksInHeap * g_pQForkControl->heapBlockSize, - PAGE_WRITECOPY, - &oldProtect) == FALSE ) { - throw std::system_error( - GetLastError(), - system_category(), - "BeginForkOperation: VirtualProtect failed for the heap"); + + // TODO: VirtualProtec randomly fails while running the cluster tests, + // retrying the call is just a workaround for the alpha release. + int retries = 0; + while (TRUE){ + BOOL result = VirtualProtect( + g_pQForkControl->heapStart, + g_pQForkControl->availableBlocksInHeap * g_pQForkControl->heapBlockSize, + PAGE_WRITECOPY, + &oldProtect); + + if (result == TRUE) { + break; + } else { + ++retries; + if (retries > 10) { + throw std::system_error( + GetLastError(), + system_category(), + "BeginForkOperation: VirtualProtect failed for the heap"); + } + redisLog(REDIS_DEBUG, "BeginForkOperation: VirtualProtect failed for the heap, retrying in 100ms."); + Sleep(100); + } } }