Memory leaks due connections left open?

Bug #2033105 reported by Petr Lefner
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-swiftclient
New
Undecided
Unassigned

Bug Description

Using swiftclient.service.SwiftService context manager object, I am observing consistently increasing memory consumption along invokes of stat() or download() methods:

while True:
    with SwiftService(...) as swift:
        for stat_futures in swift.stat(container, objects=[...]):
            ...

    sleep(1)

Note the memory impact does not change even upon moving the object outside while loop. Running a docker container executing this code, docker stats command reports consistently increasing memory usage, until process has been killed at the moment reaching container memory limit.

I have localized the cause and possible issue within swiftclient.multithreading.ConnectionThreadPoolExecutor class. Apparently, the MultiThreadingManager object, which maintains a series of thread pool executors, desires to act iself as context manager. While it invokes __exit__ on all of its executors, none of these executors empties its "connection pool" (hold by means of queue.PriorityQueue) closing stored connections first.

Indeed, upon I added following method to body of ConnectionThreadPoolExecutor, consumed memory stabilized at nearly consistent level:

    def __exit__(self, exc_type, exc_value, traceback):
        # Close all HTTP connections when the object is exited
        while not self._connections.empty():
            _, conn = self._connections.get()
            if conn is not None:
                conn.close()
        super().__exit__(exc_type, exc_value, traceback)

Maybe I am missing somtehing, as I've found no reference about how should client code be aware of pooled connections?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.