Propagate LaunchInit error code (#41380)
LaunchInit currently try catch _exit(1) all exceptions. This could cause a files system failure being reported to the user as E_UNEXPECTED instead. For example: #13028 and #13237. Where the original EIO at step 3 were collapsed to E_UNEXPECTED. This PR propagates the error out by removing LaunchInit's own try catch and rely on the caller's try catch logic. And also delays the closure of the original socket fd by setting it to CLOEXEC instead of manually close. So, the caller can still use it in catch. This PR also adds EIO (5) at step 3 to the treated as disk corruption list.
Feng Wang committed
Aug 21, 2026 at 10:25 UTC
84ec12b45957f73fe42e7f59eb17be1ed90b70ca
2 files changed
+5
-8
src/linux/init/main.cpp
+2
-7
@@ -1474,7 +1474,6 @@ Return Value:
1474
1475
--*/
1476
1477
-try
1477
{
1478
std::vector<std::string> Variables;
1479
auto AddEnvironmentVariable = [&Variables](const char* Name, const char* Value) {
@@ -1500,7 +1499,7 @@ try
1499
{
1500
THROW_LAST_ERROR_IF(TEMP_FAILURE_RETRY(dup2(SocketFd, LX_INIT_UTILITY_VM_INIT_SOCKET_FD)) < 0);
1501
1503
- close(SocketFd);
1502
+ THROW_LAST_ERROR_IF(SetCloseOnExec(SocketFd, true));
1503
SocketFd = LX_INIT_UTILITY_VM_INIT_SOCKET_FD;
1504
}
1505
else
@@ -1661,11 +1660,6 @@ try
1660
LOG_ERROR("execle({}) failed {}", LX_INIT_PATH, errno);
1661
_exit(1);
1662
}
1664
-catch (...)
1665
-{
1666
- LOG_CAUGHT_EXCEPTION();
1667
- _exit(1);
1668
-}
1663
1664
void LaunchSystemDistro(
1665
int SocketFd,
@@ -2381,6 +2375,7 @@ void ProcessLaunchInitMessage(
2375
}
2376
catch (...)
2377
{
2378
+ LOG_CAUGHT_EXCEPTION();
2379
ReportStatus(wil::ResultFromCaughtException());
2380
_exit(1);
2381
}
src/windows/service/exe/WslCoreInstance.cpp
+3
-1
@@ -66,7 +66,9 @@ WslCoreInstance::WslCoreInstance(
66
if (result.Result != 0)
67
{
68
// N.B. EFSBADCRC (74) or EFSCORRUPTED (117) can be returned if the disk's journal is corrupted.
69
- if ((result.Result == EINVAL || result.Result == 74 || result.Result == 117) && result.FailureStep == LxInitCreateInstanceStepMountDisk)
69
+ // EIO (5) can be returned during LaunchInit if corruption is detected after the initial mount succeeds.
70
+ if (((result.Result == EINVAL || result.Result == 74 || result.Result == 117) && result.FailureStep == LxInitCreateInstanceStepMountDisk) ||
71
+ (result.Result == 5 && result.FailureStep == LxInitCreateInstanceStepLaunchInit))
72
{
73
THROW_HR(WSL_E_DISK_CORRUPTED);
74
}