Skip to content

Replace scattered state guards with a trait-based state machine - #149

Merged
SeanTAllen merged 1 commit into
mainfrom
state-machine-refactor
Aug 4, 2026
Merged

Replace scattered state guards with a trait-based state machine#149
SeanTAllen merged 1 commit into
mainfrom
state-machine-refactor

Conversation

@SeanTAllen

Copy link
Copy Markdown
Member

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 (_Handshaking, _Ready, _Closing, _Closed, _AuthFailed, _Errored, _Disposed) now implement a _SSLSessionState trait. 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 _AuthFailed and _Errored) returns None from read() and alpn_selected() without touching OpenSSL, the same way _AuthFailed already did before the refactor.

Closes #137

@SeanTAllen SeanTAllen added changelog - changed Automatically add "Changed" CHANGELOG entry on merge changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge labels Aug 4, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Aug 4, 2026
@SeanTAllen SeanTAllen removed changelog - changed Automatically add "Changed" CHANGELOG entry on merge changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge labels Aug 4, 2026
@SeanTAllen
SeanTAllen force-pushed the state-machine-refactor branch 2 times, most recently from 988809f to 78227bb Compare August 4, 2026 01:16
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
SeanTAllen force-pushed the state-machine-refactor branch from 78227bb to ec709b5 Compare August 4, 2026 01:28
@SeanTAllen
SeanTAllen merged commit 17ff892 into main Aug 4, 2026
13 checks passed
@SeanTAllen
SeanTAllen deleted the state-machine-refactor branch August 4, 2026 01:32
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Aug 4, 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.

ssl.pony needs a real state machine representation

2 participants