Skip to content

Memory Leak when creating/closing connections #1437

@blevinelrp

Description

@blevinelrp

Python: 3.12.1

Driver details:
unixODBC 2.3.11

odbcinst.ini
[ODBC]
Pooling=YES

[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.5.so.1.1
UsageCount=1
:

Minimal Code Example:

@contextlib.contextmanager
def connection(self) -> pyodbc.Connection:
    cxn = pyodbc.connect(...)
    try:
        yield cxn
    finally:
        cxn.close()

def main():
    while True:
        with connection() as cxn:
            pass
        time.sleep(.1)

main()

The above code will eventually consume 100% of the system's memory (if left to run long enough).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions