Skip to content

Send Terminate message before closing TCP connection#86

Merged
SeanTAllen merged 1 commit intomainfrom
sean/graceful-termination
Feb 11, 2026
Merged

Send Terminate message before closing TCP connection#86
SeanTAllen merged 1 commit intomainfrom
sean/graceful-termination

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

Session.close() now sends a Terminate (X) message to the PostgreSQL server before closing the TCP connection. Previously, the connection was hard-closed without notifying the server, leaving server-side resources to linger until the server detected the broken connection.

The Terminate is sent from _ConnectedState.shutdown(), covering both authentication and query phases. _SessionSSLNegotiating correctly skips it since the PostgreSQL protocol hasn't started during SSL negotiation. The send is best-effort — if the connection is already broken, it silently fails and close proceeds normally.

Design: #72

Previously, Session.close() hard-closed the TCP connection without
notifying the server. PostgreSQL clients should send a Terminate ('X')
message before disconnecting so the server can clean up resources
immediately rather than discovering the broken connection on next I/O.

The Terminate is sent from _ConnectedState.shutdown(), which covers
both _SessionConnected (authentication phase) and _SessionLoggedIn
(query phase). _SessionSSLNegotiating correctly skips Terminate since
the PostgreSQL protocol hasn't started during SSL negotiation.

The send is best-effort — if the connection is already broken, the
send silently fails and close proceeds normally.

Design: #72
@SeanTAllen SeanTAllen added the changelog - changed Automatically add "Changed" CHANGELOG entry on merge label Feb 11, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 11, 2026
@SeanTAllen SeanTAllen added changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge and removed changelog - changed Automatically add "Changed" CHANGELOG entry on merge labels Feb 11, 2026
@SeanTAllen SeanTAllen merged commit aad63fd into main Feb 11, 2026
12 checks passed
@SeanTAllen SeanTAllen deleted the sean/graceful-termination branch February 11, 2026 18:05
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 11, 2026
github-actions bot pushed a commit that referenced this pull request Feb 11, 2026
github-actions bot pushed a commit that referenced this pull request Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants