Add SSL.close() and SSLClosed for orderly TLS shutdown - #148
Merged
Conversation
SeanTAllen
added a commit
that referenced
this pull request
Aug 3, 2026
SeanTAllen
force-pushed
the
sean-allen/tls-orderly-shutdown
branch
from
August 3, 2026 05:39
e39ef29 to
d5a484e
Compare
Pony's SSL wrapper had no way to send a TLS close_notify alert. Tearing down a connection without one causes the peer to report a protocol error instead of a clean closure, and some peers treat an unannounced closure as a request failure. SSL.close() calls SSL_shutdown to queue a close_notify in the output BIO. SSLClosed is a new state that means the TLS session ended cleanly — either the peer sent close_notify (detected by read) or the consumer called close. The write side shuts down but the read side stays open so the peer's remaining data and close_notify response can still arrive. SSL_ERROR_ZERO_RETURN from SSL_read and SSL_write now produces SSLClosed instead of SSLError, giving consumers a way to distinguish a clean peer closure from a protocol failure. SSLConnection handles the new state: _do_shutdown sends the response close_notify, flushes the encrypted bytes, and closes the TCP connection. Design: ponylang/lori#348
SeanTAllen
force-pushed
the
sean-allen/tls-orderly-shutdown
branch
from
August 3, 2026 05:58
9370263 to
79c8200
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pony's SSL wrapper had no way to send a TLS
close_notifyalert. Tearing down a connection without one causes the peer to report a protocol error instead of a clean closure, and some peers (notably Go'snet/http) treat that as a request failure.SSL.close()callsSSL_shutdownto queue aclose_notifyin the output BIO.SSLClosedis a new state that means the TLS session ended cleanly — either the peer sentclose_notify(detected byread) or the consumer calledclose. The write side shuts down but the read side stays open so the peer's remaining data andclose_notifyresponse can still arrive.SSL_ERROR_ZERO_RETURNfromSSL_readandSSL_writenow producesSSLClosedinstead ofSSLError, giving consumers a way to distinguish a clean peer closure from a protocol failure. This is a breaking change: any code doing exhaustive matching onSSLStatemust add a case forSSLClosed.SSLConnectionhandles the new state:_do_shutdownsends the responseclose_notify, flushes the encrypted bytes, and closes the TCP connection.Design: ponylang/lori#348