Skip to content

hang in connection.cpp at static SqlHandlePtr getEnvHandle() #421

@ywy0003

Description

@ywy0003

Describe the bug

Consistent hang attempting to connect to database when run on Debian Linux. This same code works as expected on Windows.

I confirmed network connectivity with the following.

nc -z SQL-PD01.domain-redacted 1433
SQL-PD01.domain-redacted [10.156.65.100] 1433 (ms-sql-s) open

Below is a log listing with debug enabled for the mssql-python module.

2026-02-04 11:36:52.132, 26358, DEBUG, logging.py:368, Python, PoolingManager.disable: Attempting to disable pooling
2026-02-04 11:36:52.132, 26358, DEBUG, logging.py:368, Python, PoolingManager.disable: Pooling already disabled or closed
2026-02-04 11:36:52.132, 26358, DEBUG, logging.py:368, Python, sanitize_connection_string: Sanitizing connection string (length=196)
2026-02-04 11:36:52.133, 26358, DEBUG, logging.py:368, Python, sanitize_connection_string: Password fields masked
2026-02-04 11:36:52.133, 26358, INFO, logging.py:368, Python, Final connection string: Driver={ODBC Driver 18 for SQL Server};APP=MSSQL-Python;Database=BusinessViews;PWD=***;Server=tcp:SQL-PD01.domain-redacted,1433;UID=studentrecords_reader
2026-02-04 11:36:52.133, 26358, DEBUG, connection.cpp:22, DDBC, Allocating ODBC environment handle
2026-02-04 11:36:52.133, 26358, DEBUG, connection.cpp:24, DDBC, Function pointers not initialized, loading driver
*** hang occurs. no further log messages ***

To reproduce

Include a complete code listing (or project/solution) that we can run to reproduce the issue.

import logging
import mssql_python

from sys import argv, stdout

hostname = argv[1]
database = argv[2]
username = argv[3]
password = argv[4]

root = logging.getLogger()
root.setLevel(logging.DEBUG)

handler = logging.StreamHandler(stdout)
handler.setLevel(logging.DEBUG)
root.addHandler(handler)

mssql_python.setup_logging(output="stdout")
mssql_python.pooling(enabled=False)

connection_string = f"SERVER=tcp:{hostname},1433;DATABASE={database};UID={username};PWD={password};"
conn = mssql_python.connect(connection_string)  # hangs here

cur = conn.cursor()
result = cur.execute("SELECT @@VERSION")
for row in result:
    print(row)
cur.close()
conn.close()```


### Expected behavior
Expected a successful connection to the database, or an exception. The following is what I see when running this code on Windows.

2026-02-04 11:31:51.050, 25812, DEBUG, connection.cpp:22, DDBC, Allocating ODBC environment handle
2026-02-04 11:31:51.062, 25812, DEBUG, connection.cpp:61, DDBC, Allocating SQL Connection Handle
2026-02-04 11:31:51.062, 25812, DEBUG, connection.cpp:68, DDBC, Connecting to database
2026-02-04 11:31:51.167, 25812, DEBUG, connection.cpp:182, DDBC, Setting autocommit=0
2026-02-04 11:31:51.175, 25812, DEBUG, connection.cpp:190, DDBC, Autocommit disabled
2026-02-04 11:31:51.175, 25812, DEBUG, logging.py:368, Python, cursor: Creating new cursor - timeout=0, total_cursors=0
2026-02-04 11:31:51.175, 25812, DEBUG, connection.cpp:213, DDBC, Allocating statement handle
2026-02-04 11:31:51.175, 25812, DEBUG, logging.py:368, Python, cursor: Cursor created successfully - total_cursors=1



### Further technical details
Python version: CPython 3.14.2
SQL Server version: Microsoft SQL Server 2019 (RTM-CU32-GDR) (KB5065222) - 15.0.4445.1 (X64)
Operating system: Windows Server 2019 Datacenter 10.0 <X64> (Build 17763: ) (Hypervisor)


**Additional context**
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions