Skip to content

Conversation

@arp242
Copy link
Collaborator

@arp242 arp242 commented Jan 28, 2026

When PostgreSQL cannot fork a backend process (e.g., an external process limit), it sends a plain text error like "Ecould not fork new process for connection: Resource temporarily unavailable" before any protocol handshake. The 'E' byte gets parsed as an ErrorResponse message type, but the following bytes are plain text, not a binary length field.

This causes lib/pq to interpret ASCII text as a message length (e.g., "coul" = 0x636f756c = 1.6GB), leading to massive memory allocations and a likely OOM under connection pressure.

This fix matches libpq's behavior in fe-connect.c: if an ErrorResponse has msgLength < 8 or > 30000, treat it as a pre-protocol plain text error and read it as a null-terminated string instead.

There's a decent chance this is related to #638.

Closes #1248

When PostgreSQL cannot fork a backend process (e.g., an external process
limit), it sends a plain text error like "Ecould not fork new process
for connection: Resource temporarily unavailable" before any protocol
handshake. The 'E' byte gets parsed as an ErrorResponse message type,
but the following bytes are plain text, not a binary length field.

This causes lib/pq to interpret ASCII text as a message length (e.g.,
"coul" = 0x636f756c = 1.6GB), leading to massive memory allocations and
a likely OOM under connection pressure.

This fix matches libpq's behavior in fe-connect.c: if an ErrorResponse
has msgLength < 8 or > 30000, treat it as a pre-protocol plain text
error and read it as a null-terminated string instead.

There's a decent chance this is related to #638.
@arp242 arp242 merged commit 0ad3049 into master Jan 28, 2026
13 checks passed
@arp242 arp242 deleted the pre2 branch January 28, 2026 22:31
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.

3 participants