Skip to content

Deliver server protocol violations to the application#212

Merged
SeanTAllen merged 1 commit intomainfrom
deliver-server-protocol-violations-to-application
Apr 14, 2026
Merged

Deliver server protocol violations to the application#212
SeanTAllen merged 1 commit intomainfrom
deliver-server-protocol-violations-to-application

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

Server bytes that can't be parsed, wire-legal messages arriving in a state where they're invalid, and unexpected bytes during SSL negotiation used to silently shut the session down or crash the client with an illegal-state panic. None of that was useful to an application trying to understand why its session died.

All three paths now funnel through a new on_protocol_violation state-handler method. Pre-ready violations fire pg_session_connection_failed(ProtocolViolation) followed by pg_session_shutdown. A logged-in session with a query in flight delivers ProtocolViolation to that query's receiver (pg_query_failed / pg_prepare_failed / pg_copy_failed / pg_stream_failed / pg_pipeline_failed) before pg_session_shutdown. Queries that were merely queued still see SessionClosed.

ProtocolViolation is a single primitive in both the ConnectionFailureReason union and the ClientQueryError union. Carrying no diagnostic payload was a deliberate call — server-supplied bytes or parser state are attack vectors for log injection, DoS amplification, and running code on hostile input during error handling. Easier to add bounded symbolic detail later than to remove it once shipped.

Also folds in the junk-byte half of #206 (SSL-negotiation response byte that is neither 'S' nor 'N'). The empty-data branch of #206 remains open — that's a transport failure, not a protocol violation, and belongs to a different design decision.

Closes #205.

@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Apr 14, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 14, 2026
@SeanTAllen SeanTAllen removed the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Apr 14, 2026
@SeanTAllen SeanTAllen force-pushed the deliver-server-protocol-violations-to-application branch from ac4958b to efea539 Compare April 14, 2026 17:00
A server can send bytes we can't parse, a wire-legal message that's invalid
for the current connection state, or an unexpected byte during SSL
negotiation. Any of those used to silently shut the session down — or,
worse, crash the client process with an illegal-state panic. Neither is
useful to an application trying to understand why its session died.

Now all three route through the state's own error path: pre-ready failures
fire pg_session_connection_failed(ProtocolViolation) followed by
pg_session_shutdown; a logged-in session with a query in flight delivers
ProtocolViolation to that query's receiver before the session shuts down.
Queries that were merely queued still see SessionClosed, since only the
in-flight query directly observed the violation.

Also folds in the junk-byte half of #206 (the SSL-negotiation response
byte that is neither 'S' nor 'N'). The empty-data branch of #206 remains
open — that one is a transport failure, not a protocol violation.

Closes #205
@SeanTAllen SeanTAllen force-pushed the deliver-server-protocol-violations-to-application branch from efea539 to 653711c Compare April 14, 2026 17:15
@SeanTAllen SeanTAllen merged commit 82fcc3f into main Apr 14, 2026
8 checks passed
@SeanTAllen SeanTAllen deleted the deliver-server-protocol-violations-to-application branch April 14, 2026 17:27
@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.

Parser silent-shutdown on malformed ErrorResponse during startup

2 participants