#1652 Requests sessions stay around after a koji.ClientSession object is out of scope
Closed: Fixed 4 years ago by mikem. Opened 4 years ago by mprahl.

On the Module Build Service (MBS) backend, I've noticed hundreds of TCP connections in the "CLOSE_WAIT" state to the Koji hub. This seems to stem from the fact that koji.ClientSession objects don't close the underlying requests (as in python-requests) session after the koji.ClientSession goes out of scope. It's possible the garbage collector isn't actually destroying these koji.ClientSession objects. Interestingly enough, this only happens on Python 2.

Here is a reproducer script:

import gc
import os
import time

import koji
import psutil


def get_num_connections():
    return len(psutil.Process(os.getpid()).connections())


def get_session():
    session = koji.ClientSession('https://koji.fedoraproject.org/kojihub')
    session.getBuild(1382202)


print('Starting with {} connections'.format(get_num_connections()))
for i in range(20):
    get_session()
print(
    '{} connections after requesting 20 Koji sessions that are now out of scope'
    .format(get_num_connections())
)

gc.collect()
time.sleep(10)
print(
    '{} connections after running the garbage collector and sleeping for 10 seconds'
    .format(get_num_connections())
)

Thanks for tracking this down @mprahl

Metadata Update from @mikem:
- Custom field Size adjusted to None

4 years ago

Metadata Update from @dgregor:
- Issue set to the milestone: 1.19

4 years ago

Metadata Update from @dgregor:
- Issue assigned to mprahl

4 years ago

Login to comment on this ticket.

Metadata
Related Pull Requests
  • #1653 Merged 4 years ago