You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OF-2425: Stream Management on server connections, phase 1: refactor the existing implementation without changing its behaviour - #3549
This is the first pull request for OF-2425, which adds Stream Management (XEP-0198) to connections between Openfire and other servers. The first commit adds the engineering plan for this work, which splits it into phases of one pull request each. This PR contains the implementation of the first phase
Server connections will reuse the existing client implementation in StreamManager. That code assumed it serves a client, used client/server naming that will be the wrong way around once Openfire also opens connections and asks for Stream Management, and had little test coverage. This phase first records the current behaviour in tests, and then refactors the code without changing what it does. Each commit can be reviewed on its own.
For plugins, renamed or moved public members remain as deprecated delegates. One change has no delegate: StreamManager is now abstract, so its constructor is protected.
…erver connections
Implementing XEP-0198 for server connections spans many pull requests, and work on it is split over separate sessions that each need to start from the same design decisions and task descriptions. Those were not recorded in the repository.
The plan describes the approach, the design decisions and the implementation sessions, grouped in phases. Sessions record their progress in the plan's frontmatter.
No functional change.
The plan put all of Stream Management in StreamManager, which only ever answered requests of the peer. Once Openfire also asks a remote server to enable Stream Management, on connections that it opens, the code for asking and the code for answering would sit side by side in one class. Nothing would tie a stream to one of the two, so a remote server could also enable Stream Management on a connection that Openfire opened, whatever the settings.
A new design decision makes StreamManager a base class for what both ends of a stream share, with a subclass for the end that answers and one for the end that asks. Each end then has its code in one place, and what it refuses follows from its class. What happens when a session is resumed, or closes without being resumed, is implemented per end, as the end that asks handles unacknowledged stanzas differently. Two sessions are added to phase 1: one that introduces the base class and the subclass for the end that answers, and one that arranges the tests by the class they test. The sessions that follow are adjusted to the new classes, and the shared tests are run against both ends once both exist.
The plan also takes in what was recorded in it while the first sessions were worked on, such as the bugs that block phases, their state, and open questions found along the way. Its session status reflects that work.
… acknowledgements
StreamManager had little test coverage for enabling Stream Management, answering <r/> and requesting acknowledgements. The fixes for OF-3433 and OF-3434 added tests for the processing of <a/>, the roll-over at 2^32 and the maximum number of unacknowledged stanzas, but not for these. Reusing this code for server connections requires refactoring it, which needs a record of what it does now.
StreamManagerTest now also covers enabling with and without resumption in both namespaces, the attributes of <enabled/>, the count of handled stanzas in the answer to <r/>, how often <r/> is sent, and the acknowledgements that are ignored: those without a value, those on a stream without Stream Management, and those for stanzas sent before it was enabled. The mock client session now has a non-anonymous authentication token, so that it can be made resumable.
No functional change.
…ssions
Resumption, and what happens to a session that is not resumed, had little test coverage, while later phases of the plan reuse this code for server connections. The new tests describe the behaviour that XEP-0198 requires:
- StreamManagerResumptionTest covers a successful resumption (the reattached session, the closing of a former stream that is still open, the 'previd' and 'h' of <resumed/>, and the stanzas that are sent again: in order, after <resumed/>, with a delay element, and followed by a request for acknowledgement), refused resumptions (an unknown session or stream, a malformed 'previd', a session on another cluster node, an anonymous, unauthenticated or bound session, a closed session, a stream of which resumption was disabled, another namespace and a value of 'h' that is too high), and what happens to the unacknowledged stanzas of a stream that is not resumed (XEP-0198 § 4).
- SessionManagerDetachedSessionTest covers the detaching of a resumable session when its connection closes, and the ending of a detached session after xmpp.session.detach.timeout.
Where XEP-0198 does not define the error condition of a refused resumption, the tests expect the current one. For a 'previd' that cannot be decoded, the current condition is unexpected-request, while XEP-0198 § 5 recommends item-not-found. The test records this deviation. The tests for unacknowledged stanzas include the rules that OF-3442 introduced: an unacknowledged IQ request is answered with a service-unavailable error, and unacknowledged stanzas are handled after the session is removed.
The tests are in new classes, separate from StreamManagerTest. Messages that are delivered on a connection that has closed can be handled twice, by the backup deliverer of the connection and again by Stream Management. This is recorded as an open question in the plan. Session 2 is marked as completed. No production code is changed.
…ion instead of client and server
StreamManager named its counters, its queue of unacknowledged stanzas and its acknowledgement methods after the client and the server, such as serverProcessedStanzas and processClientAcknowledgement. That only holds while Openfire is the server end of the stream. Once Openfire opens server connections and takes the role that clients have today, the names would be the wrong way around.
They are now named after the direction of the stanzas: inbound for those that Openfire receives from the peer, outbound for those that it sends to the peer. For example, serverProcessedStanzas is now handledInboundStanzas, unacknowledgedServerStanzas is unacknowledgedOutboundStanzas, sendServerAcknowledgement() is acknowledgeInboundStanzas() and processClientAcknowledgement() is processOutboundAcknowledgement(). Javadoc and log messages that used client and server in this sense now refer to the peer. Text that refers to the client role itself, such as for enabling and resuming Stream Management, and the text of stream errors that are sent to the peer, are unchanged.
The two methods that were public, sendServerAcknowledgement() and incrementServerProcessedStanzas(), remain as deprecated delegates to their new names, for removal in or after Openfire 5.3.0, so that plugins that use them keep working (decision 8 of the plan). The tests only change where they refer to the renamed fields and methods. Session 3 is marked as completed. No functional change.
…ager into its own class
StreamManager kept the stanzas that the peer had not acknowledged in a deque that it manipulated directly, together with the count of acknowledged stanzas and whether that count rolled over, the numbering of sent stanzas, the processing of acknowledgements and the check for the maximum. Outgoing server sessions need the same tracking, which was not available separately.
This is now done by UnacknowledgedStanzaQueue, to which StreamManager delegates. The class is package-private, as only StreamManager uses it. Each of its entries has room to record that the stanza was sent again, which is not used yet. It logs through the logger of the StreamManager that uses it, so that its log messages still name the session. What happens when the maximum is exceeded remains in StreamManager, which closes the stream.
StreamManager calls the queue under the same locks as before, which keep a sequence of calls consistent. In addition, each method of the queue holds the lock of the queue, and the entries are returned as a copy instead of a view, so that a single call is safe from any thread. This covers the places where StreamManager reads the last unacknowledged stanza for an error message without its own lock, which could fail when another thread emptied the queue at the same time. While the queue holds its lock, it calls nothing that takes the lock of StreamManager, so the two locks cannot deadlock.
StreamManager.UnackedPacket is no longer used, and remains as a deprecated class without a replacement, for removal in or after Openfire 5.3.0 (decision 8 of the plan). The tests in StreamManagerTest only change where they refer to the moved validation and counter. UnacknowledgedStanzaQueueTest tests the new class. Session 4 is marked as completed.
No functional change.
…mption from StreamManager
StreamManager assumed that every resumable session is a client session: it checked the AuthToken of a LocalClientSession to decide whether a session may resume, built the SM-ID from the resource and the stream ID, and found the session to resume through the client routes. Server sessions need their own rules for each of these.
These parts are now behind the Resumption interface. StreamManager creates an implementation for its session, chosen by session type. ClientResumption holds the existing client rules, including the removal of detached sessions elsewhere in the cluster (OF-2753). It logs through the logger of the StreamManager that uses it, so that its log messages still name the session. Other session types get an implementation that refuses resumption, as before. The checks that do not depend on the session type, such as the state of the session to resume and its Stream Management namespace and 'h', remain in StreamManager.
StreamManager now keeps the SM-ID that it creates when resumption is enabled, and uses it for the 'previd' of <resumed/>, instead of creating it a second time. An implementation therefore does not need to produce the same SM-ID on every call.
The SM-ID, and the fields that record whether the stream can be resumed and which namespace it uses, are volatile. The thread of the connection that resumes a stream reads them from the stream manager of another session, without holding its lock.
The inline SASL2 resume flow requires ClientResumption, as SASL2 is only used by clients, and refuses other session types as before. Refusals that were not logged are now logged at debug level: a resume request for a session whose stream ID does not match, an inline resume request from a session that is not a client session, and a request to enable resumption from a session that may not resume. This is the one place where StreamManager still refers to LocalClientSession, as Sasl2ResumeResult returns the resumed client session. ResumptionTest tests ClientResumption and the implementation for other session types directly. StreamManagerResumptionTest also covers resume requests, traditional and inline, from a session that is not a client session. Session 5 is marked as completed.
No functional change.
…anager class
StreamManager handled everything about Stream Management on a stream: the acknowledgements and the queue of unacknowledged stanzas, which are the same at both ends of a stream, but also the requests of the peer to enable Stream Management or to resume a stream, which only the end that answers handles. That suited Openfire while it only answered such requests. Once it also asks for Stream Management, on connections that it opens to other servers, code for both ends would have to live side by side in one class, with nothing to tie a stream to one of them.
StreamManager is now an abstract base class for what both ends share. AnsweringStreamManager holds what the end that answers does: processing requests to enable Stream Management and to resume a stream, inline resumption with SASL2, and what happens when its session is resumed or closes without being resumed. StreamManager.forSession creates the stream manager for a session, which is an AnsweringStreamManager for every session for now. Client sessions and sessions of servers that connect to Openfire return that type from getStreamManager(), so that code calling its methods does not need a cast.
The constructor of StreamManager is now protected, as an abstract class cannot be created; this is an API change for plugins that create a stream manager themselves, which Openfire itself only does when it creates a session. The methods that moved remain on StreamManager as deprecated delegates. No functional change.
The tests of Stream Management stayed where they were when the end of a stream that answers requests of the peer moved into AnsweringStreamManager, so that a diff with only changed references showed that the move kept behaviour. As a result, StreamManagerTest mixed tests of what both ends of a stream share with tests of the answering end, StreamManagerResumptionTest only tested the answering end, and someone changing AnsweringStreamManager would not find its tests by name. The tests of the validation of acknowledgements also still carried client and server in their names, for what is now named after direction.
The tests of enabling Stream Management, of resume requests, of building the resumed element, of detaching a session that is resumed elsewhere and of what happens to unacknowledged stanzas when a session closes are now in AnsweringStreamManagerTest, and StreamManagerResumptionTest is renamed to AnsweringStreamManagerResumptionTest. Of the tests of what both ends share, those that need a resumption or a detached session that is ended are in StreamManagerDetachedSessionTest, as the end that asks for Stream Management cannot be resumed yet; the others remain in StreamManagerTest. The fixture and helpers that these classes share moved to a common base class, so that no test changed other than in its name.
One test is added. No test covered a Stream Management element that the answering end does not process, such as <enabled/>, which is answered with 'unexpected-request'. That answer now depends on AnsweringStreamManager reporting to StreamManager that it did not process the element, so AnsweringStreamManagerTest now covers it.
The change separates shared Stream Management state from negotiation and resumption handling. It adds an unacknowledged-stanza queue with acknowledgement validation and rollover handling. A session-specific manager now handles enable requests, traditional and SASL2 resumption, and close-time stanza processing. Session wiring and inbound acknowledgement calls are updated, and tests are added or reorganized for these behaviors.
Possibly related PRs
igniterealtime/Openfire#3542: Changes resume and acknowledgement error handling in code paths that this refactor relocates to AnsweringStreamManager.
igniterealtime/Openfire#3529: Implements overlapping acknowledgement validation and rollover behavior that this change moves into UnacknowledgedStanzaQueue.
Suggested reviewers:bobatron, viv
Pre-merge checks: 3
Check name
Status
Explanation
Description check
The description states that this PR is phase one of OF-2425, which adds Stream Management (XEP-0198) to server-to-server connections. It says the phase records existing client-side behaviour in tests …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description states that this PR is phase one of OF-2425, which adds Stream Management (XEP-0198) to server-to-server connections. It says the phase records existing client-side behaviour in tests and then refactors StreamManager without changing behaviour. It also notes that renamed public members remain as deprecated delegates and that the StreamManager constructor is now protected. These points match the changeset, which adds AnsweringStreamManager, UnacknowledgedStanzaQueue, and Resumption, makes StreamManager abstract, and adds and reorganizes tests.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Review coverage is incomplete: 1 file could not be fully reviewed. Findings from completed review steps are included; see review info for details.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Extend AbstractStreamManagerTest instead of copying its helpers.
This class redefines helpers that AbstractStreamManagerTest already provides:
resumableClientSession()
resumingClientSession()
mockCloseTracking()
lastDelivered()
unacknowledgedMessageIds()
The copies have already diverged. This version of resumableClientSession() registers the session in the class field routingTable. The shared version creates a new mocked XMPPServer with its own routing table. A later fix to one copy will not reach the other copy.
Make this class extend AbstractStreamManagerTest. Remove the duplicated helpers. Keep only the helpers that are specific to this class, such as reattached(), routed(), iq() and assertFailed(). If a test needs the class-level routingTable stub, change the shared fixture to expose its routing table.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 7a93a039-5eba-4c1d-8428-6f62b552eac7
Commits
Reviewing files that changed from the base of the PR and between e868403 and 043df2f.
Files not fully reviewed because their changes were unavailable: 1
doc/plan/2026-10-23-stream-management-s2s.md
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
I've compared the refactor with main: the public API (apart from the constructor you mention), enabling, the validation of resume requests, the SM-ID in <resumed/>, onClose, and the numbering, roll-over and timestamps in UnacknowledgedStanzaQueue. I found no change in behaviour. The tests added before the refactor pass against the old code as well, so they describe what main does.
One thing in the plan: "Open Questions" still describes the session that SASL EXTERNAL authentication continues with as an open problem on main. That is OF-3447 now, fixed in #3544, so should it move to "Blocking Issues", next to the phase it blocks? That section currently says all four issues are merged.
Superseded by #3565, which contains this refactoring as its first commits, together with the remaining phases of OF-2425. The commits were reorganised, but the code they arrive at is the same apart from the removal of the duplicated test helpers that CodeRabbit flagged.
@viv thanks for comparing the refactor with main. The engineering plan is no longer part of the pull request; the design decisions are recorded as ADRs 007–009 instead. OF-3447 is handled in #3544, which is still open.
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
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.
This is the first pull request for OF-2425, which adds Stream Management (XEP-0198) to connections between Openfire and other servers. The first commit adds the engineering plan for this work, which splits it into phases of one pull request each. This PR contains the implementation of the first phase
Server connections will reuse the existing client implementation in
StreamManager. That code assumed it serves a client, used client/server naming that will be the wrong way around once Openfire also opens connections and asks for Stream Management, and had little test coverage. This phase first records the current behaviour in tests, and then refactors the code without changing what it does. Each commit can be reviewed on its own.For plugins, renamed or moved public members remain as deprecated delegates. One change has no delegate:
StreamManageris now abstract, so its constructor is protected.