Retry to delete distribution VHD for up to 10 seconds (#41153)
Blue committed
Jul 23, 2026 at 15:36 UTC
81a3508382a35615b7631eee6c3fff3dd48cc84b
1 file changed
+10
-1
src/windows/service/exe/LxssUserSession.cpp
+10
-1
@@ -3005,7 +3005,16 @@ void LxssUserSessionImpl::_DeleteDistributionLockHeld(_In_ const LXSS_DISTRO_CON
3005
3006
if (WI_IsFlagSet(Flags, LXSS_DELETE_DISTRO_FLAGS_VHD))
3007
{
3008
- LOG_IF_WIN32_BOOL_FALSE(DeleteFileW(Configuration.VhdFilePath.c_str()));
3008
+ // The VHD might be in use so try to delete it for up to 10 seconds.
3009
+ try
3010
+ {
3011
+ wsl::shared::retry::RetryWithTimeout<void>(
3012
+ [&]() { THROW_IF_WIN32_BOOL_FALSE(DeleteFileW(Configuration.VhdFilePath.c_str())); },
3013
+ std::chrono::milliseconds(100),
3014
+ std::chrono::seconds(10),
3015
+ []() { return wil::ResultFromCaughtException() == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION); });
3016
+ }
3017
+ CATCH_LOG_MSG("Failed to delete %ls", Configuration.VhdFilePath.c_str())
3018
}
3019
}
3020
}