You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Handle pre-protocol errors to prevent memory exhaustion
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.
0 commit comments