MerginMaps / MerginMaps/python-api-client

MerginProject may not get cleaned up properly

Open
#149 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
23
Forks
12
Avg merge
2d 13h
Merged PRs (30d)
7

Description

When MerginProject is created, it creates geodiff object and assigns an internal logger to geodiff. This creates a cyclic reference (pygeodiff refs MerginProject, and MerginProject refs pygeodiff) that may keep resources held, which may be a problem if MerginProject object is created many times. See also fix for this in db-sync: https://github.com/MerginMaps/mergin-db-sync/pull/79

Also somehow related: https://github.com/MerginMaps/geodiff/issues/190

Code snippet to replicate the cleanup issue:

import pygeodiff

class MerginProjectX:

    def __init__(self, directory):

        def _logger_callback(level, text_bytes):
            self.x()   # not a real function, but refs this object...

        self.geodiff = pygeodiff.GeoDiff()
        self.geodiff.set_logger_callback(_logger_callback)

# this will keep consuming more and more resources
for i in range(50000):
    print(i)
    mp = MerginProjectX("x")
    #mp.geodiff = None    # this helps to break ref cycle
    time.sleep(0.005)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating MerginProject's pygeodiff GeoDiff creation and logger-callback setup, then compare the cleanup fix in mergin-db-sync PR 79 and the related geodiff issue 190. Done means repeated MerginProject creation no longer retains the cyclic references or causes resources to grow, using the reproduction loop to verify cleanup.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.