Skip to content

fix libpq nonblocking connect readiness#1372

Closed
russellromney wants to merge 1 commit into
QuarkContainer:mainfrom
russellromney:codex/psycopg-nonblocking-connect
Closed

fix libpq nonblocking connect readiness#1372
russellromney wants to merge 1 commit into
QuarkContainer:mainfrom
russellromney:codex/psycopg-nonblocking-connect

Conversation

@russellromney

Copy link
Copy Markdown

Summary

Fix two TCP readiness issues that break libpq/psycopg's nonblocking connect path under Quark:

  • Clear the select(2) exception fdset entry itself when no exception event occurred.
  • When uring TCP getsockopt(SO_ERROR) only has cached EINPROGRESS, ask the host socket for the current SO_ERROR; if the host reports success, clear the cached state and promote the socket through PostConnect().

Root cause

psycopg/libpq opens the TCP socket nonblocking, receives EINPROGRESS from connect(2), and then immediately checks getsockopt(SO_ERROR) before sending the PostgreSQL startup packet. Quark was still returning cached EINPROGRESS until a later readiness path advanced the uring socket state.

A separate select fdset typo caused sockets to appear in the exception fdset even after SO_ERROR was clear.

Validation

Validated through Tinyhost's real droplet e2e against postgres:16-alpine:

SOCKET connect_ex=115 immediate_so_error=0 select_read=False select_write=True select_except=False so_error=0
RESULT quark/socket PASS
RESULT quark/pg8000 PASS
RESULT quark/psycopg PASS
root=clear; quark libpq nonblocking connect works against real Postgres
62_QUARK_PSYCOPG_OK

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.

1 participant