Skip to content

feat(psycopg): add support for Windows via TCP loopback proxy - #1471

Open
kgala2 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
kgala2:feat-psycopg-windows
Open

feat(psycopg): add support for Windows via TCP loopback proxy#1471
kgala2 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
kgala2:feat-psycopg-windows

Conversation

@kgala2

@kgala2 kgala2 commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds Windows OS support for the psycopg (v3) database driver in the Cloud SQL Python Connector.

Context & Implementation

  • Windows Support: psycopg (via libpq) does not support Unix domain sockets on Windows. When running on Windows (platform.system() == "Windows"), the connector creates a local TCP loopback listener on 127.0.0.1 with an OS-allocated ephemeral port (port=0), passes host="127.0.0.1", port=ephemeral_port to psycopg.connect(), and proxies data over the established TLS connection.
  • POSIX Systems: Retains the existing Unix domain socket (AF_UNIX) approach in a user-isolated temporary directory (tempfile.mkdtemp()).
  • Tests:
    • Removed the not hasattr(socket, "AF_UNIX") test skips across unit and system tests.
    • Updated mockable_socketpair() to dynamically use the socket family (s1.family) so tests execute cleanly on both Windows (AF_INET) and POSIX (AF_UNIX).
    • Added unit test test_connect_wrapper_windows verifying the Windows TCP loopback path and port assignment.
    • Maintains 100% test coverage for google.cloud.sql.connector.psycopg.

Testing

  • pytest tests/unit/test_psycopg.py --cov=google.cloud.sql.connector.psycopg (100% coverage, 24/24 tests passing)
  • pytest tests/unit/ (197/197 unit tests passing)
  • ruff check and ruff format passed.

@kgala2
kgala2 requested a review from a team as a code owner August 26, 2026 23:44
@kgala2
kgala2 marked this pull request as draft August 26, 2026 23:47
@kgala2
kgala2 marked this pull request as ready for review August 27, 2026 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants