Skip to content

fix(postgresql-proxy): prevent SSL COPY stalls by draining pending SSL buffer#12

Merged
nik-localstack merged 2 commits into
masterfrom
unc-472-fix-ssl-copy-stall
May 13, 2026
Merged

fix(postgresql-proxy): prevent SSL COPY stalls by draining pending SSL buffer#12
nik-localstack merged 2 commits into
masterfrom
unc-472-fix-ssl-copy-stall

Conversation

@nik-localstack
Copy link
Copy Markdown

Motivation

Fixes UNC-472: Postgres proxy could hang for sslmode=require sessions running large psql -f / COPY-heavy workloads.

Root cause

selector.select() operates at the TCP layer and is unaware of data already decrypted and buffered inside the SSL layer. After an initial recv(), buffered SSL bytes would not be seen by the next select() call, stalling large transfers.

Changes (postgresql_proxy/proxy.py)

  • After each recv() in service_connection(), drain any remaining SSL-buffered bytes using sock.pending() (per Python SSL non-blocking docs).
  • Add explicit setblocking(True) on accepted sockets before SSL negotiation. On macOS/BSD, accepted sockets inherit O_NONBLOCK from the listening socket (unlike Linux), causing intermittent BlockingIOError on the MSG_PEEK recv ~1/10 times during SSL startup.

Expected impact

Prevents SSL COPY-session stalls for large dump-like workloads without changing the proxy's overall non-blocking architecture.

nik-localstack and others added 2 commits May 12, 2026 11:53
…g reads

Co-authored-by: GitHub Copilot <copilot@github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@cloutierMat cloutierMat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nik-localstack for the working on that fix and reducing the PR size. I will get to reviewing the stacked PR soon. In the meantime this is GTG. Let's push and publish! 🤘

@nik-localstack nik-localstack merged commit 5ade47a into master May 13, 2026
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