Skip to content

Commit 86d9d36

Browse files
committed
Fix deadlock on WSL removal after installing Docker
1 parent 5d081d6 commit 86d9d36

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

client/hostinfo_wsl.cpp

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "boinc_win.h"
2222
#include "win_util.h"
2323

24+
#include "error_numbers.h"
2425
#include "str_replace.h"
2526
#include "client_state.h"
2627
#include "client_msgs.h"
@@ -51,8 +52,12 @@ int get_all_distros(WSL_DISTROS& distros) {
5152
LONG lRet = RegOpenKeyEx(HKEY_CURRENT_USER,
5253
lxss_path.c_str(), 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hKey
5354
);
55+
if (lRet == ERROR_FILE_NOT_FOUND) {
56+
msg_printf(0, MSG_INFO, "WSL: registry key not found; assuming no WSL distros are installed");
57+
return 0;
58+
}
5459
if (lRet != ERROR_SUCCESS) {
55-
msg_printf(0, MSG_INFO, "WSL: registry open failed");
60+
msg_printf(0, MSG_INFO, "WSL: registry open failed (error %ld)", lRet);
5661
return -1;
5762
}
5863

@@ -64,8 +69,9 @@ int get_all_distros(WSL_DISTROS& distros) {
6469
(LPBYTE)default_wsl_guid, &default_wsl_guid_len
6570
);
6671
if ((lRet != ERROR_SUCCESS) || (default_wsl_guid_len > buf_len)) {
67-
msg_printf(0, MSG_INFO, "WSL: registry query failed");
68-
return -1;
72+
msg_printf(0, MSG_INFO, "WSL: registry query for DefaultDistribution failed (error %ld)", lRet);
73+
RegCloseKey(hKey);
74+
return 0;
6975
}
7076

7177
// scan subkeys (one per distro)
@@ -97,6 +103,7 @@ int get_all_distros(WSL_DISTROS& distros) {
97103
hSubKey, "State", NULL, NULL, (LPBYTE)&wsl_state, &wsl_state_len
98104
);
99105
if (ret != ERROR_SUCCESS || wsl_state != 1) {
106+
RegCloseKey(hSubKey);
100107
continue;
101108
}
102109

@@ -196,16 +203,21 @@ int get_wsl_information(WSL_DISTROS &distros) {
196203
WSL_DISTROS all_distros;
197204
int retval = get_all_distros(all_distros);
198205
if (retval) return retval;
206+
if (all_distros.distros.empty()) {
207+
distros.distros.clear();
208+
return 0;
209+
}
199210
string err_msg;
200211

201212
WSL_CMD rs;
202213

203214
if (rs.setup(err_msg)) {
204-
msg_printf(0, MSG_INFO, "WSL setup error: %s", err_msg.c_str());
205-
return -1;
215+
msg_printf(0, MSG_INFO, "WSL unavailable: %s", err_msg.c_str());
216+
return 0;
206217
}
207218

208219
string reply;
220+
bool launch_failed = false;
209221

210222
// loop over all WSL distros
211223
for (WSL_DISTRO &wd: all_distros.distros) {
@@ -234,6 +246,9 @@ int get_wsl_information(WSL_DISTROS &distros) {
234246
);
235247
CloseHandle(rs.proc_handle);
236248
update_os(wd, os_name, os_version);
249+
} else {
250+
launch_failed = true;
251+
break;
237252
}
238253

239254
// try reading '/etc/os-relese'
@@ -249,16 +264,17 @@ int get_wsl_information(WSL_DISTROS &distros) {
249264
);
250265
CloseHandle(rs.proc_handle);
251266
update_os(wd, os_name, os_version);
267+
} else {
268+
launch_failed = true;
269+
break;
252270
}
253271
}
254272

255273
// try reading '/etc/redhatrelease'
256274
//
257275
if (!got_both(wd)) {
258276
const std::string command_redhatrelease = "cat " + std::string(file_redhatrelease);
259-
if (!rs.run_program_in_wsl(
260-
wd.distro_name, command_redhatrelease
261-
)) {
277+
if (!rs.run_program_in_wsl(wd.distro_name, command_redhatrelease)) {
262278
read_from_pipe(rs.out_read, rs.proc_handle, reply, CMD_TIMEOUT);
263279
HOST_INFO::parse_linux_os_info(
264280
reply, redhatrelease,
@@ -267,6 +283,9 @@ int get_wsl_information(WSL_DISTROS &distros) {
267283
);
268284
CloseHandle(rs.proc_handle);
269285
update_os(wd, os_name, os_version);
286+
} else {
287+
launch_failed = true;
288+
break;
270289
}
271290
}
272291

@@ -287,6 +306,9 @@ int get_wsl_information(WSL_DISTROS &distros) {
287306
);
288307
CloseHandle(rs.proc_handle);
289308
update_os(wd, os_name_str.c_str(), os_version_str.c_str());
309+
} else {
310+
launch_failed = true;
311+
break;
290312
}
291313
}
292314

@@ -301,6 +323,9 @@ int get_wsl_information(WSL_DISTROS &distros) {
301323
strip_whitespace(os_name_str);
302324
CloseHandle(rs.proc_handle);
303325
update_os(wd, os_name_str.c_str(), "");
326+
} else {
327+
launch_failed = true;
328+
break;
304329
}
305330
}
306331

@@ -315,6 +340,9 @@ int get_wsl_information(WSL_DISTROS &distros) {
315340
strip_whitespace(os_version_str);
316341
CloseHandle(rs.proc_handle);
317342
update_os(wd, "", os_version_str.c_str());
343+
} else {
344+
launch_failed = true;
345+
break;
318346
}
319347
}
320348

@@ -372,6 +400,11 @@ int get_wsl_information(WSL_DISTROS &distros) {
372400
distros.distros.push_back(wd);
373401
}
374402

403+
if (launch_failed) {
404+
msg_printf(0, MSG_INFO, "WSL commands cannot be launched; skipping WSL detection");
405+
distros.distros.clear();
406+
}
407+
375408
return 0;
376409
}
377410

lib/win_util.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,17 @@ int WSL_CMD::setup_podman(const char* distro_name) {
266266
int WSL_CMD::run_program_in_wsl(
267267
const string distro_name, const string command, bool use_cwd
268268
) {
269+
proc_handle = NULL;
269270
HRESULT ret = pWslLaunch(
270271
boinc_ascii_to_wide(distro_name).c_str(),
271272
boinc_ascii_to_wide(command).c_str(),
272273
use_cwd, in_read, out_write, out_write,
273274
&proc_handle
274275
);
275276
if (ret != S_OK) {
276-
fprintf(stderr, "pWslLaunch failed: %d\n", ret);
277+
fprintf(stderr, "pWslLaunch failed: 0x%08lx\n", ret);
278+
proc_handle = NULL;
279+
return ERR_NOT_FOUND;
277280
}
278281
return 0;
279282
}

0 commit comments

Comments
 (0)