Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
value, so a conflicting former name cannot change that prefixed cache entry. CI, the documentation and
`TestOptionsConfiguration` use the new names.

- Remove the Windows agent's native profile after a forced exit (#439): when WebView2 processes still held the profile
at the end of the 2 s in-process retry, the agent exited and left it behind, so `AutomationCliWatchdog` failed
intermittently on loaded runners. A detached agent process now retries removal for about 20 s, including for Unicode
paths and paths containing shell metacharacters. The watchdog test waits for the cleanup window, and its second CLI
invocation has a 45 s limit instead of 15 s.

## 0.6.0 - 2026-10-31

- Build the React store tests in Release with GCC 16 (#429): at -O2 and above, GCC reported the moved-from path of
Expand Down
52 changes: 52 additions & 0 deletions js/developer/tools/WebFrontAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,52 @@ void releaseWebView(std::chrono::milliseconds grace) noexcept {
// Without the process list, the removal below still retries the transient errors.
}
}
// A separate agent process can retry after a forced exit without interpreting the profile path as shell syntax.
bool removeAfterExit(const std::filesystem::path& path) noexcept {
try {
std::wstring executable(32768, L'\0');
const DWORD length = GetModuleFileNameW(nullptr, executable.data(), static_cast<DWORD>(executable.size()));
if (!length || length >= executable.size())
return false;
executable.resize(length);
const std::wstring original = L"\"" + executable + L"\" --cleanup-profile \"" + path.wstring() + L"\"";
STARTUPINFOW startup{};
startup.cb = sizeof startup;
PROCESS_INFORMATION information{};
for (const DWORD breakaway : {DWORD{CREATE_BREAKAWAY_FROM_JOB}, DWORD{0}}) {
auto command = original; // CreateProcessW may modify the command line even on failure.
if (CreateProcessW(executable.c_str(), command.data(), nullptr, nullptr, FALSE,
CREATE_NO_WINDOW | DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP | breakaway, nullptr, nullptr,
&startup, &information)) {
CloseHandle(information.hThread);
CloseHandle(information.hProcess);
return true;
}
}
return false;
} catch (...) {
return false;
}
}

int cleanupProfile() {
// The launcher supplies a quoted path as the final argument. Read the Unicode command line directly: argv uses the
// process code page and cannot represent every Windows path.
const std::wstring command = GetCommandLineW();
const std::wstring marker = L" --cleanup-profile \"";
const auto begin = command.find(marker);
if (begin == std::wstring::npos || command.back() != L'"')
return 1;
const std::filesystem::path path{command.substr(begin + marker.size(), command.size() - begin - marker.size() - 1)};
for (int attempt = 0; attempt != 20; ++attempt) {
std::error_code error;
std::filesystem::remove_all(path, error);
if (!error)
return 0;
std::this_thread::sleep_for(std::chrono::seconds{1});
}
return 1;
}
#elif defined(__linux__)
// The parent and state ('Z' for a zombie) of a process, from /proc/<pid>/stat; nothing when it is gone.
std::optional<std::pair<pid_t, char>> processStat(pid_t pid) {
Expand Down Expand Up @@ -406,6 +452,8 @@ struct Profile {
std::this_thread::sleep_for(std::chrono::milliseconds{20});
continue;
}
if (removeAfterExit(path))
return;
#endif
std::cerr << "Automation: cannot remove temporary profile: " << error.message() << '\n';
return;
Expand Down Expand Up @@ -657,6 +705,10 @@ Options parse(int argc, char** argv) {

int main(int argc, char** argv) {
try {
#ifdef _WIN32
if (argc == 3 && std::string_view(argv[1]) == "--cleanup-profile")
return cleanupProfile();
#endif
#ifndef _WIN32
std::signal(SIGPIPE, SIG_IGN);
#endif
Expand Down
36 changes: 33 additions & 3 deletions test/tools/AutomationClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ def profile_directory():
rather than an inherited TMPDIR, which may be long: Chromium's singleton socket path must stay below sockaddr_un's
limit."""
root = "/tmp" if sys.platform.startswith("linux") and os.access("/tmp", os.W_OK | os.X_OK) else None
path = tempfile.mkdtemp(prefix="wf-profile-", dir=root)
path = tempfile.mkdtemp(prefix="wf-profile- &%!^ 雪 " if sys.platform == "win32" else "wf-profile-", dir=root)
try:
yield path
finally:
shutil.rmtree(path, ignore_errors=True)


def remaining_profiles(profiles, timeout=10, settle=2.5):
def remaining_profiles(profiles, timeout=25, settle=2.5):
"""The agent profiles left in `profiles`, once absent for `settle` seconds or after `timeout` more, with what
they contain.

Expand All @@ -155,6 +155,34 @@ def remaining_profiles(profiles, timeout=10, settle=2.5):
time.sleep(0.05)


def check_windows_profile_cleaner(agent, root):
"""A locked file must be retried, including when its Unicode path contains shell metacharacters."""
if sys.platform != "win32":
return
import ctypes
from ctypes import wintypes
profile = root / "profile &%!^ 雪"
profile.mkdir()
file = profile / "locked"
file.write_text("locked")
kernel = ctypes.WinDLL("kernel32", use_last_error=True)
kernel.CreateFileW.argtypes = [wintypes.LPCWSTR, wintypes.DWORD, wintypes.DWORD, wintypes.LPVOID,
wintypes.DWORD, wintypes.DWORD, wintypes.HANDLE]
kernel.CreateFileW.restype = wintypes.HANDLE
kernel.CloseHandle.argtypes = [wintypes.HANDLE]
handle = kernel.CreateFileW(str(file), 0x80000000, 0, None, 3, 0, None)
if handle == wintypes.HANDLE(-1).value:
raise ctypes.WinError(ctypes.get_last_error())
try:
cleaner = subprocess.Popen([agent, "--cleanup-profile", str(profile)])
time.sleep(3)
assert cleaner.poll() is None, "Cleaner stopped while the profile was locked"
finally:
kernel.CloseHandle(handle)
assert cleaner.wait(timeout=10) == 0
assert not profile.exists(), "Cleaner left the profile behind"


def check_startup_backoff(agent, root, ready_delay=0):
"""The attach-only path needs no renderer and must not create 50 connections per second."""
endpoint = root / f"owner-{ready_delay}"
Expand Down Expand Up @@ -263,6 +291,8 @@ def watchdog(args):
pathlib.Path(args.work).mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(dir=args.work, prefix="watchdog-") as temporary:
root = pathlib.Path(temporary)
if args.scenario == "cli-watchdog":
check_windows_profile_cleaner(args.agent, root)
project = root / "project"
shutil.copytree(args.fixture, project)
environment = root / "watchdog-environment.tgz"
Expand Down Expand Up @@ -344,7 +374,7 @@ def watchdog(args):
failed_command[failed_command.index("--environment") + 1] = str(failed_environment)
failed_command[failed_command.index("--integrity") + 1] = "sha512-" + base64.b64encode(hashlib.sha512(failed_environment.read_bytes()).digest()).decode()
failed = subprocess.run([args.agent, *failed_command, "--listen", str(endpoint), "--operation", "build"],
capture_output=True, text=True, encoding="utf-8", timeout=15)
capture_output=True, text=True, encoding="utf-8", timeout=45)
assert failed.returncode == 70, (failed.returncode, failed.stdout, failed.stderr)
assert "Automation startup: B" + "é" * 511 + "\n" in failed.stderr, failed.stderr
assert not endpoint.exists()
Expand Down
Loading