Skip to content

Fix session crash on server rejection during startup#207

Merged
SeanTAllen merged 2 commits intomainfrom
fix-203-connection-failure-unification
Apr 14, 2026
Merged

Fix session crash on server rejection during startup#207
SeanTAllen merged 2 commits intomainfrom
fix-203-connection-failure-unification

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

Server startup rejections like max_connections exhaustion previously crashed the process through an unreachable-state panic instead of reaching the application. Root cause: the two-bucket failure taxonomy (pg_session_authentication_failed vs pg_session_connection_failed) didn't match how PostgreSQL actually fails — any server ErrorResponse with an unmapped SQLSTATE reached _IllegalState().

This PR consolidates the two callbacks into pg_session_connection_failed, expands ConnectionFailureReason with SQLSTATE-specific variants, and centralizes SQLSTATE → variant mapping in _ConnectionFailureReasonFromError so no server error can reach _IllegalState() again. pg_session_shutdown now fires after every pg_session_connection_failed so consumers see a consistent "session torn down" signal regardless of which phase failed.

Design: comment on #203. Follow-up issues for pre-existing silent-failure paths discovered during review: #204 (SCRAM signature verification bypass), #205 (parser malformed-ErrorResponse silent shutdown), #206 (SSL-negotiation junk-byte silent shutdown).

Breaking API change for a beta library — migration notes are in the release notes.

Closes #203

Server startup rejections like max_connections exhaustion crashed
through an unreachable-state panic instead of reaching the application.
Root cause: the two-bucket failure taxonomy (authentication_failed vs
connection_failed) didn't match how PostgreSQL actually fails — any
server ErrorResponse with an unmapped SQLSTATE reached _IllegalState().

Consolidate the two callbacks into pg_session_connection_failed,
expand ConnectionFailureReason with SQLSTATE-specific variants, and
centralize the mapping so no server error can reach _IllegalState()
again. Fire pg_session_shutdown after every connection_failed so the
"session torn down" signal is consistent across all failure phases.

Closes #203
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 14, 2026
@SeanTAllen SeanTAllen merged commit 278634d into main Apr 14, 2026
7 checks passed
@SeanTAllen SeanTAllen deleted the fix-203-connection-failure-unification branch April 14, 2026 03:07
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Apr 14, 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.

Session panics on ErrorResponse when max_connections exceeded

2 participants