#1652 Requests sessions stay around after a koji.ClientSession object is out of scope
Closed: Fixed by mikem. Opened 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())
)

I've submitted a potential fix at:
https://pagure.io/koji/pull-request/1653

Thanks for tracking this down @mprahl

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

Commit a5af69c9 fixes this issue

Commit a552a248 fixes this issue

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

Metadata Update from @dgregor:
- Issue assigned to mprahl

This issue has been migrated to Fedora Forge:
https://forge.fedoraproject.org/koji/koji/issues/1652

Please continue any further discussion there.

Metadata
Related Pull Requests