Skip to content

Commit

Permalink
Revert "Fix pr #6620: Fix memory leak in JSON encoder"
Browse files Browse the repository at this point in the history
This reverts commit 3ec5f32.
  • Loading branch information
xingyaoww authored and openhands-agent committed Feb 5, 2025
1 parent cf2874a commit 4a7556d
Showing 1 changed file with 13 additions and 42 deletions.
55 changes: 13 additions & 42 deletions openhands/runtime/browser/browser_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,51 +207,22 @@ def check_alive(self, timeout: float = 60):
logger.debug(f'Browser env is not alive. Response ID: {response_id}')

def close(self):
if not self.process.is_alive():
return
try:
# Always try to send shutdown signal if process is alive
self.agent_side.send(('SHUTDOWN', None))
self.process.join(5) # Wait for the process to terminate
if self.process.is_alive():
try:
self.agent_side.send(('SHUTDOWN', None))
self.process.join(5) # Wait for the process to terminate
except Exception:
pass

# Force terminate if still alive
logger.error(
'Browser process did not terminate, forcefully terminating...'
)
self.process.terminate()
self.process.join(5) # Wait for the process to terminate
if self.process.is_alive():
logger.error(
'Browser process did not terminate, forcefully terminating...'
)
try:
self.process.terminate()
self.process.join(5) # Wait for the process to terminate
except Exception:
pass

# Force kill if still alive
if self.process.is_alive():
try:
self.process.kill()
self.process.join(5) # Wait for the process to terminate
except Exception:
pass

# Always try to close pipes, even if process is not alive
try:
self.agent_side.close()
except Exception:
pass
try:
self.browser_side.close()
except Exception:
pass

# Ensure process is terminated
if self.process.is_alive():
logger.error('Failed to terminate browser process')
try:
self.process.kill() # Final attempt
except Exception:
pass
self.process.kill()
self.process.join(5) # Wait for the process to terminate
self.agent_side.close()
self.browser_side.close()
except Exception as e:
logger.error(f'Encountered an error when closing browser env: {e}')

Expand Down

0 comments on commit 4a7556d

Please sign in to comment.