Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: handle os.kill on Windows for process checking#4129

Open
hztBUAA wants to merge 2 commits intobrowser-use:mainfrom
hztBUAA:fix/windows-os-kill
Open

fix: handle os.kill on Windows for process checking#4129
hztBUAA wants to merge 2 commits intobrowser-use:mainfrom
hztBUAA:fix/windows-os-kill

Conversation

@hztBUAA
Copy link

@hztBUAA hztBUAA commented Feb 20, 2026

Summary

  • Fix _is_process_alive() and _kill_process() in browser_use/skill_cli/tunnel.py to work on Windows by adding sys.platform == 'win32' guards with ctypes.windll.kernel32.OpenProcess / TerminateProcess fallbacks
  • This matches the existing Windows-compatible pattern already used in utils.py and main.py (_pid_exists and kill_orphaned_server)
  • os.kill(pid, 0) raises SystemError on Windows because signal 0 is not supported; os.kill(pid, signal.SIGKILL) also fails since SIGKILL is Unix-only

Fixes #3912

Test plan

  • Verify _is_process_alive() correctly detects running/dead processes on Windows
  • Verify _kill_process() can terminate cloudflared tunnel processes on Windows
  • Verify existing Unix behavior is unchanged (os.kill path still used on Linux/macOS)

Summary by cubic

Fix Windows process detection and termination in tunnel.py by using Win32 APIs instead of os.kill. Prevents crashes from unsupported signals and keeps Unix behavior unchanged.

  • Bug Fixes
    • _is_process_alive now uses OpenProcess on Windows; os.kill(pid, 0) on Unix.
    • _kill_process now uses TerminateProcess on Windows; Unix still sends SIGTERM, waits briefly, then SIGKILL.
    • Matches the Windows-safe pattern in utils.py and main.py to avoid SystemError and SIGKILL issues.

Written for commit 891c237. Summary will update on new commits.

The _is_process_alive and _kill_process functions in tunnel.py used
os.kill(pid, 0) and os.kill(pid, signal.SIGKILL) which fail on Windows.
Added sys.platform checks with ctypes fallbacks matching the pattern
already used in utils.py and main.py.

Fixes browser-use#3912
@CLAassistant
Copy link

CLAassistant commented Feb 20, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ laithrw
❌ hztBUAA
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@hztBUAA
Copy link
Author

hztBUAA commented Feb 25, 2026

Thanks for the review and feedback. I am following up on this PR now and will either push the requested changes or reply point-by-point shortly.

@hztBUAA
Copy link
Author

hztBUAA commented Feb 25, 2026

Quick follow-up: I am reviewing the feedback and will update this PR shortly.

@laithrw
Copy link
Member

laithrw commented Mar 1, 2026

@hztBUAA, thank you for the PR; it looks good. Please sign the Contributor License Agreement so I can merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

browser-use Windows Issue - os.kill(pid, 0) - Fails on Windows

3 participants