Hello,

We may have hit the same problem. On Windows, a backend intermittently
stops waking up for data the client has already sent. In our case it
happens during authentication, so the connection hangs until
authentication_timeout. Your case (hang after connecting, certificate
authentication, localhost) could be the same state hitting the first
query instead, where nothing times out.

We traced it to the Windows socket event handling in
WaitEventSetWaitBlock() and reported it as BUG #19972, with a reproducer
that works on demand on 15.19 and 19.0:
https://www.postgresql.org/message-id/[email protected]

If you can still reproduce your hang, a stack of the hung server backend
(the postgres.exe process for that connection, not the client) would
show whether it is waiting in WaitForMultipleObjects under secure_read.
That would confirm it is the same bug.

Regards,
Stephen L. De Rudder

From: shashi B savarn <[email protected]>
Sent: Monday, June 22, 2026 3:19 AM
To: [email protected]
Subject: Intermittent hang in SQLConnect (ODBC, PostgreSQL 15, Windows)


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.

Reply via email to