Retry to delete WSL distribution shortcut for up to 10 seconds (#41046)
Blue committed
Jul 10, 2026 at 11:03 UTC
0ed515a27c8bd0c7f71836f2ab94c1603649f1a4
1 file changed
+10
-2
src/windows/service/exe/LxssUserSession.cpp
+10
-2
@@ -3014,8 +3014,16 @@ void LxssUserSessionImpl::_DeleteDistributionLockHeld(_In_ const LXSS_DISTRO_CON
3014
// Remove start menu entry for the distribution, if any.
3015
if (Configuration.ShortcutPath.has_value())
3016
{
3017
- LOG_IF_WIN32_BOOL_FALSE_MSG(
3018
- DeleteFileW(Configuration.ShortcutPath->c_str()), "Failed to delete %ls", Configuration.ShortcutPath->c_str());
3017
+ // The shortcut file may be in use. Try to delete it for up to 10 seconds, and then give up.
3018
+ try
3019
+ {
3020
+ wsl::shared::retry::RetryWithTimeout<void>(
3021
+ [&]() { THROW_IF_WIN32_BOOL_FALSE(DeleteFileW(Configuration.ShortcutPath->c_str())); },
3022
+ std::chrono::milliseconds(100),
3023
+ std::chrono::seconds(10),
3024
+ []() { return wil::ResultFromCaughtException() == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION); });
3025
+ }
3026
+ CATCH_LOG_MSG("Failed to delete %ls", Configuration.ShortcutPath->c_str())
3027
}
3028
3029
// Remove the terminal profile, if any.