Replace scattered state guards with a trait-based state machine - #149
Merged
Conversation
SeanTAllen
force-pushed
the
state-machine-refactor
branch
2 times, most recently
from
August 4, 2026 01:16
988809f to
78227bb
Compare
The SSL class checked `_ssl.is_null()` and compared `_state` at the top of every method, with each site making its own decisions about which states allowed which operations. The scattered guards had already diverged: `read()` and `alpn_selected()` on an `SSLError` session called into OpenSSL when they should have returned `None`, matching how `SSLAuthFail` already behaved. Seven internal state classes now implement a `_SSLSessionState` trait. The SSL class delegates every operation to the current state, and Pony's type system enforces that every state handles every operation. Closes #137
SeanTAllen
force-pushed
the
state-machine-refactor
branch
from
August 4, 2026 01:28
78227bb to
ec709b5
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.
The SSL class checked
_ssl.is_null()and compared_stateat the top of every method, with each site making its own decisions about which states allowed which operations. The scattered guards had already diverged:read()andalpn_selected()on anSSLErrorsession called into OpenSSL when they should have returnedNone, matching howSSLAuthFailalready behaved.Seven internal state classes (
_Handshaking,_Ready,_Closing,_Closed,_AuthFailed,_Errored,_Disposed) now implement a_SSLSessionStatetrait. The SSL class delegates every operation to the current state. Each state defines the complete behavior for its lifecycle phase, and Pony's type system enforces that every state handles every operation.The two bugs fall out of the new structure:
_FailedSSLState(shared by_AuthFailedand_Errored) returnsNonefromread()andalpn_selected()without touching OpenSSL, the same way_AuthFailedalready did before the refactor.Closes #137