fix: add Windows-compatible process checks in tunnel.py#4292
Open
giulio-leone wants to merge 4 commits intobrowser-use:mainfrom
Open
fix: add Windows-compatible process checks in tunnel.py#4292giulio-leone wants to merge 4 commits intobrowser-use:mainfrom
giulio-leone wants to merge 4 commits intobrowser-use:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
2 issues found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="browser_use/skill_cli/tunnel.py">
<violation number="1" location="browser_use/skill_cli/tunnel.py:168">
P2: Windows process liveness check misclassifies `OpenProcess` access-denied failures as dead, causing live tunnel metadata to be deleted.</violation>
<violation number="2" location="browser_use/skill_cli/tunnel.py:180">
P2: Windows kill path reports success without checking whether `TerminateProcess` actually succeeded, which can hide failed termination and orphan tunnel processes.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
5da0de6 to
d5fbdec
Compare
added 3 commits
March 9, 2026 15:17
tunnel.py was the only remaining file using raw os.kill(pid, 0) for process existence checks, which fails on Windows with a SystemError. The same fix was already applied to utils.py and main.py but missed in tunnel.py. Changes: - _is_process_alive(): Use ctypes.windll.kernel32.OpenProcess on Windows, matching the pattern in utils.py and main.py - _kill_process(): Use ctypes.windll.kernel32.TerminateProcess on Windows instead of signal.SIGTERM/SIGKILL which are not supported Fixes browser-use#3912
Address review feedback: - _is_process_alive: check GetLastError() for ERROR_ACCESS_DENIED (5), which means the process exists but we lack permissions to open it. Previously this was misclassified as 'dead'. - _kill_process: check TerminateProcess return value instead of unconditionally returning True, which could hide failed termination.
- Log warning when process termination fails in stop_tunnel - Capture GetLastError immediately after OpenProcess
d5fbdec to
66da712
Compare
Contributor
Author
|
Friendly ping — CI is green, tests pass, rebased on latest. Ready for review whenever convenient. Happy to address any feedback. 🙏 |
…dows - Switch from ctypes.windll.kernel32.GetLastError() to ctypes.WinDLL with use_last_error=True + ctypes.get_last_error() so the error code from OpenProcess is captured atomically rather than via a second Win32 call that can return a stale value. - After TerminateProcess succeeds, poll _is_process_alive to confirm the process has actually exited before returning True. TerminateProcess is asynchronous; returning True without verification can hide orphaned tunnel processes. - Log a warning with the Win32 error code when TerminateProcess fails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3912
tunnel.pywas the only remaining file using rawos.kill(pid, 0)for process existence checks, which fails on Windows with aSystemError. The same fix was already applied toutils.pyandmain.py(which usectypes.windll.kernel32.OpenProcesson Windows) but was missed intunnel.py.Changes
_is_process_alive()sys.platform == 'win32'check withctypes.windll.kernel32.OpenProcess()utils.py:_pid_exists()andmain.py:_pid_exists()_kill_process()ctypes.windll.kernel32.TerminateProcess()signal.SIGTERMandsignal.SIGKILLare not supported on WindowsRoot Cause
os.kill(pid, 0)is Unix-specific for process existence checks. On Windows, it raisesSystemErrorinstead of working as expected. This broke all tunnel-related CLI operations on Windows (start, stop, status).Testing
os.kill(pid, 0)path)ctypesapproach already proven inutils.pyandmain.pySummary by cubic
Make tunnel process checks and kills work on Windows in
tunnel.py. Fixes #3912 and restores tunnel start/stop/status on Windows.WinDLL(..., use_last_error=True).OpenProcess; treatERROR_ACCESS_DENIED (5)as alive; Unix still usesos.kill(pid, 0).TerminateProcess, check the return code, then poll to verify the process exited; log the Win32 error on failure. Unix still sendsSIGTERM, thenSIGKILL.Written for commit 6e675df. Summary will update on new commits.