Intermittent hang in SQLConnect (ODBC, PostgreSQL 15, Windows)

From: shashi B savarn <shashi(dot)savarn(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Intermittent hang in SQLConnect (ODBC, PostgreSQL 15, Windows)
Date: 2026-06-22 08:19:19
Message-ID: CA+4uE8JyjKfGuZP2c_XDtxdd6O65q+RHDJRr5=Q6UOHcRLErVg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

We are encountering an intermittent issue where our Windows-based
application hangs indefinitely during SQLConnect when connecting to a
PostgreSQL server via ODBC.
Environment

- PostgreSQL version: 15.0.15.25315
- ODBC driver: psqlODBC 16.00.0007
- Connection type: ODBC using certificate-based authentication
- Deployment: Application and PostgreSQL server both run on the same
machine (localhost)

Application Behavior

- The application maintains:
- Some long-lived persistent connections
- A few short-lived connections (3–4) that are opened/closed
periodically
- Connection pooling is enabled (we also tested with pooling disabled
and reduced timeouts—no change)

Configuration

- Connection timeout is explicitly set before calling SQLConnect
- TCP keepalive parameters are configured
- Both settings are visible in PostgreSQL ODBC trace logs

Issue Description

On a subset of systems, intermittently (roughly once a week, sometimes more
frequently), the SQLConnect call:

- Hangs indefinitely
- Does not return or timeout

Observations / Troubleshooting

- Initially suspected Microsoft Defender or network filtering:
- Added PostgreSQL data directory to exclusions → no improvement
- No network filtering/firewall issues observed
- Adjusted connection pooling and timeout values → no impact

Call Stack During Hang

mswsock!WSPStartup
mswsock!WSPStartup
ws2_32!select
libpq!PQsocketPoll
libpq!PQsocketPoll
libpq!PQgetResult
psqlodbc35w!Ordinal94
psqlodbc35w!Ordinal94
psqlodbc35w!Ordinal94
psqlodbc35w!SQLConnectW
odbc32!SQLConnectW
odbc32!ODBCSetTryWaitValue
comsvcs!DispManGetContext
comsvcs!DispManGetContext
odbc32!SQLDriverConnectW
odbc32!SQLDriverConnectW
odbc32!SQLFreeStmt
odbc32!SQLConnectW
odbc32!SQLConnect

From the stack, it appears the hang occurs in:

- libpq!PQsocketPoll / PQgetResult, which eventually blocks in
- ws2_32!select

This suggests the thread is waiting on a socket event during connection
establishment (possibly SSL/certificate handshake or server response).
Questions

- Has anyone experienced similar behavior with PostgreSQL 15 and
psqlODBC on Windows?
- Are there known issues where SQLConnect can block indefinitely despite
configured timeouts?
- Could this be related to libpq socket polling behavior or SSL/cert
authentication edge cases?

Any insights or suggestions for further diagnostics would be greatly
appreciated.

Thanks in advance.

Browse pgsql-general by date

  From Date Subject
Next Message Scot Kreienkamp 2026-06-22 13:42:21 RE: set failover=true on existing logical replication slot PG18
Previous Message Matthias Apitz 2026-06-22 05:56:39 PostgreSQL server with SSL