question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak on linux inside Docker for a trivial ui

See original GitHub issue

Specification

  • Platform: linux (inside docker container)
  • Version: 2.1

Description

After running a very simple UI for few minutes, memory grows to hundreds of MB (and GB after longer period of time). It’s basically enough call the api from javascript in a loop. I’m attaching python code (with requirements.txt), html and dockerfile for reproduction.

NOTE: I haven’t seen this problem on the newest version (2.2.1), but as it has different system requirements (uses webkit2) we can’t update.

ui.py:

import threading
import webview

class Api:
    def getStatus(self, params):
        return None

def read_file(file):
    with open(file, "r", encoding="utf-8") as f:
        return f.read()

def read_html():
    return read_file("index.html")

def create_app():
    webview.load_html(read_html())

def main():
    t = threading.Thread(target=create_app)
    t.start()
    api = Api()
    webview.create_window("UI", js_api=api)
    t.join()

if __name__ == "__main__":
    main()

index.html:

<!DOCTYPE html>
<html>
<body id="body">
<scrilpt>
    function checkMagicLoaderStatus() {
        pywebview.api.getStatus();
    }
    window.setInterval(checkMagicLoaderStatus, 20);
</scrilpt>
</body>
</html>

requirements.txt:

requests==2.19.1
PyGObject==3.30.1
pywebview==2.1
pytest==3.8.1
pyrsistent==0.14.4

Dockerfile:

FROM python:3.7.0

WORKDIR /usr/src/app

RUN apt-get update
RUN apt-get install -y libgirepository1.0-dev gir1.2-webkit-3.0 libcanberra-gtk-module libcanberra-gtk3-module

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# suppress GTK warnings about accessibility because there's no dbus
ENV NO_AT_BRIDGE 1

COPY . .

CMD [ "python", "./ui.py" ]

Commands to build and run:

docker -- build . -t ${DOCKER_IMAGE}:${DOCKER_TAG}
docker run -it -e DISPLAY -v $XAUTHORITY:/root/.Xauthority --net=host ${DOCKER_IMAGE}:${DOCKER_TAG}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kgrygielcommented, Jun 26, 2019

For the record, I believe the source of the leak is this code:

# Backup the doc title and store the result in it with a custom prefix
unique_id = uuid1().hex
code = 'window.oldTitle{0} = document.title; document.title = {1};'.format(unique_id, script)

It creates a new variable with a unique name each time. The fix would be to delete window.oldTitle{0} after use.

0reactions
r0x0rcommented, Jul 12, 2019

@kgrygiel You are indeed correct. As newer version does not seem to have this memory leak and backporting webkit 1 is likely not to happen anytime soon, I am closing this PR. It is good to have a solution documented though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging Memory Leaks in a Containerised Node Application
Find out how to debug memory leaks in a Docker-based React/Node app, using Prometheus, Grafana, Chrome's Node inspector and Locust.
Read more >
Memory Leak on ridiculously simple repo · Issue #7874 - GitHub
Running many test files causes a memory leak. I created a stupid simple repo with only Jest installed and 40 tautological test files....
Read more >
9. Finding Memory Leaks - VisIt User Manual
We support several mechanisms to find memory leaks. The two best mechanisms are using Valgrind and vtkDebugLeaks. Valgrind is used to detect memory...
Read more >
Docker daemon memory leak due to logs from long running ...
Docker daemon memory leak has been talked about in this issue and this issue. But both of them are closed now saying merged...
Read more >
Debugging RAM: Detect/Fix Memory Leaks in Managed ...
In this article, I'll walk you through debugging memory usage. ... This is an interesting native tool to debug memory leaks in Linux...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found