OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

[Bug]: Memory leak when switching/initializing agents, probably due to Browser

Open rbren opened this issue 1 year ago • 3 comments

Is there an existing issue for the same bug?

  • [X] I have checked the troubleshooting document at https://opendevin.github.io/OpenDevin/modules/usage/troubleshooting
  • [X] I have checked the existing issues.

Describe the bug

If you open the settings modal repeatedly, and switch your settings up to cause a re-init of the agent, the server slowly consumes more and more memory

I had to do this ~50 times before my machine became unresponsive.

When I finally quit, I get a bunch of logs like this:

11:47:33 - opendevin:INFO: browser_env.py:69 - Browser env process interrupted by user.
11:47:33 - opendevin:INFO: browser_env.py:69 - Browser env process interrupted by user.
11:47:33 - opendevin:INFO: browser_env.py:69 - Browser env process interrupted by user.
11:47:33 - opendevin:INFO: browser_env.py:69 - Browser env process interrupted by user.
11:47:34 - opendevin:INFO: browser_env.py:69 - Browser env process interrupted by user.
INFO:     Shutting down
11:47:34 - opendevin:INFO: browser_env.py:69 - Browser env process interrupted by user.
INFO:     Waiting for background tasks to complete. (CTRL+C to force quit)
11:47:34 - opendevin:INFO: browser_env.py:69 - Browser env process interrupted by user.

Current Version

On main


commit ce7c7eaae45ce18a13081e63d013a7123bbe95d3 (HEAD -> main, origin/main, origin/HEAD)
Author: Robert Brennan <[email protected]>
Date:   Thu May 2 11:44:54 2024 -0400

    Refactor actions and observations (#1479)


### Installation and Configuration

```bash
Running in dev mode

Model and Agent

Various models and agents as I switched around

Reproduction Steps

  1. Fire up the UI
  2. Open settings modal
  3. Change something and save
  4. Repeat ~50 times
  5. Your machine will grind to a halt

Logs, Errors, Screenshots, and Additional Context

No response

rbren avatar May 02 '24 15:05 rbren

@frankxu2004 any immediate thoughts here? I'm not 100% sure it's the browser, but it seems like the most likely culprit

rbren avatar May 02 '24 15:05 rbren

Most likely the browser env processes are not closed. Would you mind ps -aux | grep playwright when you have a lot of initialization of agents? I will take a look later today.

frankxu2004 avatar May 02 '24 17:05 frankxu2004

Can reproduce. Every time it re-initializes the agent, a new AgentController is initialized, a new BrowserEnv is created, and thus the underlying browser process. The old AgentController instances are not GCed as their sid still seem valid. I am not 100% sure but I wonder what happened to the previous sessions?

frankxu2004 avatar May 05 '24 08:05 frankxu2004