feat(server): add ConnectionHandler trait for connection lifecycle hooks#1194
Merged
Benoît Cortier (CBenoit) merged 2 commits intoDevolutions:masterfrom Apr 8, 2026
Merged
Conversation
Add optional ConnectionHandler to RdpServer::run() with two callbacks: - on_accept(peer) -> bool: called after accept(), return false to reject - on_disconnected(peer, duration, error) -> PostConnectionAction: called after run_connection() completes, return Stop to exit the accept loop This enables server implementations to add pre-accept filtering (rate limiting, IP allowlists), post-disconnect cleanup (session validity checks, metrics), and controlled shutdown when external state becomes invalid (e.g. compositor session terminated). Both methods have default implementations that accept all connections and continue unconditionally, so existing callers are unaffected.
There was a problem hiding this comment.
Pull request overview
This PR introduces a configurable connection lifecycle hook mechanism for ironrdp-server by adding an optional ConnectionHandler to RdpServer::run(), enabling pre-accept filtering and post-disconnect actions (including controlled shutdown of the accept loop).
Changes:
- Added
ConnectionHandlertrait with defaulton_accept/on_disconnectedlifecycle callbacks andPostConnectionActionfor post-disconnect control flow. - Wired the handler into the
RdpServer::run()accept loop (reject-before-run and stop-after-disconnect behaviors). - Extended the server builder with
with_connection_handler()and plumbed the handler intoRdpServer::new().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/ironrdp-server/src/server.rs | Defines ConnectionHandler / PostConnectionAction and integrates callbacks into the accept loop. |
| crates/ironrdp-server/src/builder.rs | Adds builder plumbing to configure and pass a ConnectionHandler into RdpServer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Move per-connection cleanup above the ConnectionHandler callback so it runs even when on_disconnected returns PostConnectionAction::Stop.
Benoît Cortier (CBenoit)
approved these changes
Apr 8, 2026
Member
Benoît Cortier (CBenoit)
left a comment
There was a problem hiding this comment.
Perfect! Thank you!
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.
Summary
Add optional
ConnectionHandlertoRdpServer::run()with two lifecycle callbacks:on_accept(peer) -> bool: called afteraccept(), returnfalseto reject the connection beforerun_connection()on_disconnected(peer, duration, error) -> PostConnectionAction: called afterrun_connection()completes, returnStopto exit the accept loopThis enables server implementations to add:
Both methods have default implementations that accept all connections and continue unconditionally, so existing callers are unaffected.
Motivation
lamco-rdp-servercurrently duplicates the entirerun()accept loop (~100 lines) to add connection lifecycle hooks for D-Bus event emission, PAM peer IP tracking, and Portal session validity checks. WithConnectionHandler, it can adopt the upstreamrun()directly.The key gap was
PostConnectionAction::Stop: after each client disconnects, lamco checks whether the Wayland compositor session is still valid and stops accepting if not. The existingServerEvent::Quitmechanism requires the handler to know about IronRDP internals;PostConnectionActionkeeps the contract explicit.Changes
server.rs:ConnectionHandlertrait,PostConnectionActionenum,connection_handlerfield onRdpServer, hooks wired intorun()accept loopbuilder.rs:with_connection_handler()onBuilderDone,ConnectionHandlerimport,BuilderDonefieldTest plan
Stop: accept loop exits after disconnecton_accept: connection dropped, loop continues