snowflakedb / snowflakedb/snowflake-connector-python

SNOW-2920022: SessionManager leaks memory due to defaultdict usage for sessions map

Open
#2,727 4 comments 0 reactions 1 assignee View on GitHub

@sfc-gh-snow-drivers-warsaw-dl is already working on this.

Since Jan 1, 2026.

bug status-triage_done
Dominant language
Python
Stars
730
Forks
574
Avg merge
5h 45m
Merged PRs (30d)
16

Description

While developing https://github.com/Snowflake-Labs/django-snowflake and after fixing #2725, a Django test reveals that SessionManager.__init__() leaks memory due to defaultdict usage for the SessionManager._sessions_map:

======================================================================
FAIL: test_select_related_memory_leak (select_related.tests.SelectRelatedTests.test_select_related_memory_leak)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/tests/select_related/tests.py", line 149, in test_select_related_memory_leak
    self.assert_no_memory_leaks()
  File "/home/tim/code/django/tests/select_related/tests.py", line 73, in assert_no_memory_leaks
    self.assertEqual(gc.garbage, [])
AssertionError: Lists differ: [<snowflake.connector.session_manager.Sess[330 chars] {})] != []

First list contains 5 additional elements.
First extra element 0:
<snowflake.connector.session_manager.SessionManager object at 0x7bb6daff8dd0>

+ []
- [<snowflake.connector.session_manager.SessionManager object at 0x7bb6daff8dd0>,
-  <cell at 0x7bb6daffb6a0: SessionManager object at 0x7bb6daff8dd0>,
-  (<cell at 0x7bb6daffb6a0: SessionManager object at 0x7bb6daff8dd0>,),
-  <function SessionManager.__init__.<locals>.<lambda> at 0x7bb6dad16160>,
-  defaultdict(<function SessionManager.__init__.<locals>.<lambda> at 0x7bb6dad16160>, {})]

I'm not sure how to fix this offhand.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.