Skip to content

Add SSL.close() and SSLClosed for orderly TLS shutdown - #148

Merged
SeanTAllen merged 1 commit into
mainfrom
sean-allen/tls-orderly-shutdown
Aug 3, 2026
Merged

Add SSL.close() and SSLClosed for orderly TLS shutdown#148
SeanTAllen merged 1 commit into
mainfrom
sean-allen/tls-orderly-shutdown

Conversation

@SeanTAllen

@SeanTAllen SeanTAllen commented Aug 3, 2026

Copy link
Copy Markdown
Member

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 (notably Go's net/http) treat that 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. This is a breaking change: any code doing exhaustive matching on SSLState must add a case for SSLClosed.

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

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Aug 3, 2026
SeanTAllen added a commit that referenced this pull request Aug 3, 2026
@SeanTAllen
SeanTAllen force-pushed the sean-allen/tls-orderly-shutdown branch from e39ef29 to d5a484e Compare August 3, 2026 05:39
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
SeanTAllen force-pushed the sean-allen/tls-orderly-shutdown branch from 9370263 to 79c8200 Compare August 3, 2026 05:58
@SeanTAllen
SeanTAllen merged commit 37b2757 into main Aug 3, 2026
13 checks passed
@SeanTAllen
SeanTAllen deleted the sean-allen/tls-orderly-shutdown branch August 3, 2026 05:59
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Aug 3, 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.

2 participants