Fix resource leaks: unclosed file handles and sockets#210
Fix resource leaks: unclosed file handles and sockets#210hobostay wants to merge 1 commit intobrowser-use:mainfrom
Conversation
Multiple file handles and sockets were never closed, causing resource leaks especially in the long-running daemon process: - capture_screenshot: open().write() never closed the file handle - daemon log(): open().write() leaked a file descriptor per log call - daemon PID write: open().write() leaked a file handle - _send(): socket leaked if an exception occurred before close() - ensure_daemon() stale probe: socket never closed in any path - restart_daemon(): socket leaked if exception occurred before close() Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Hi, admin.restart_daemon() still reads the PID file via open(pid_path).read() without closing the file handle, leaking a descriptor on the success path. This undermines the PR’s stated goal of eliminating resource leaks and can accumulate if restart_daemon() is called repeatedly (e.g., from ensure_daemon()). Severity: remediation recommended | Category: reliability How to fix: Use context manager for PID Agent prompt to fix - you can give this to your LLM of choice:
Found by Qodo code review |
Summary
withstatements for file operations andtry/finallyfor socket cleanupIssues Fixed
File handle leaks:
helpers.pycapture_screenshot():open().write()pattern never closed the file handledaemon.pylog():open().write()leaked a file descriptor on every log call — critical in a long-running daemondaemon.py__main__: PID file write leaked a file handleSocket leaks:
helpers.py_send(): socket leaked if an exception occurred befores.close()admin.pyensure_daemon(): stale-daemon probe socket never closed in any code path (success or exception)admin.pyrestart_daemon(): socket leaked if an exception occurred befores.close()Test plan
🤖 Generated with Claude Code
Summary by cubic
Fixes file and socket resource leaks to stop file descriptor growth and improve daemon stability. All file handles and UNIX sockets are now properly closed.
withfor file writes indaemon.log, PID creation, andhelpers.capture_screenshot.try/finallyinhelpers._send,admin.ensure_daemon, andadmin.restart_daemon.Written for commit f04d753. Summary will update on new commits.