@samitouri / QOSAMI-WSL / commits / e36dd323

Retry distro file deletion under ACCESS_DENIED (#41274)

Blue committed Aug 6, 2026 at 23:41 UTC e36dd323f22a9c81e26d57bdb8b28fe3b7adbf9c
2 files changed +17 -2
src/shared/inc/retryshared.h
+15
@@ -40,4 +40,19 @@ T RetryWithTimeout(const std::function<T()>& routine, TPeriod retryPeriod, TTime
40 }
41 }
42
43 +#ifdef WIN32
44 +
45 +template <typename T, typename TPeriod, typename TTimeout>
46 +T RetryWithTimeout(const std::function<T()>& routine, TPeriod retryPeriod, TTimeout timeout, std::vector<HRESULT>&& retryErrors)
47 +{
48 + auto pred = [retryErrors = std::move(retryErrors)]() {
49 + auto hr = HRESULT_FROM_WIN32(GetLastError());
50 + return std::find(retryErrors.begin(), retryErrors.end(), hr) != retryErrors.end();
51 + };
52 +
53 + return RetryWithTimeout(routine, retryPeriod, timeout, pred);
54 +}
55 +
56 +#endif
57 +
58 } // namespace wsl::shared::retry
src/windows/service/exe/LxssUserSession.cpp
+2 -2
@@ -3040,7 +3040,7 @@ void LxssUserSessionImpl::_DeleteDistributionLockHeld(_In_ const LXSS_DISTRO_CON
3040 [&]() { THROW_IF_WIN32_BOOL_FALSE(DeleteFileW(Configuration.VhdFilePath.c_str())); },
3041 std::chrono::milliseconds(100),
3042 std::chrono::seconds(10),
3043 - []() { return wil::ResultFromCaughtException() == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION); });
3043 + {HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)});
3044 }
3045 CATCH_LOG_MSG("Failed to delete %ls", Configuration.VhdFilePath.c_str())
3046 }
@@ -3066,7 +3066,7 @@ void LxssUserSessionImpl::_DeleteDistributionLockHeld(_In_ const LXSS_DISTRO_CON
3066 [&]() { THROW_IF_WIN32_BOOL_FALSE(DeleteFileW(Configuration.ShortcutPath->c_str())); },
3067 std::chrono::milliseconds(100),
3068 std::chrono::seconds(10),
3069 - []() { return wil::ResultFromCaughtException() == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION); });
3069 + {HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)});
3070 }
3071 CATCH_LOG_MSG("Failed to delete %ls", Configuration.ShortcutPath->c_str())
3072 }