Skip to content

Comments

Fix SessionFuture completion and ChannelFsm listener lifecycle bugs#1637

Merged
kevinherron merged 3 commits into1.0from
session-fsm-fixes
Oct 31, 2025
Merged

Fix SessionFuture completion and ChannelFsm listener lifecycle bugs#1637
kevinherron merged 3 commits into1.0from
session-fsm-fixes

Conversation

@kevinherron
Copy link
Contributor

Complete pending SessionFuture instances when session creation is aborted via CloseSession events. The CreatingWait → Inactive and ReactivatingWait → Closing transitions now call handleFailureToOpenSession() to ensure any GetSession or OpenSession futures are properly completed with Bad_SessionClosed exceptions.

Prevent ChannelFsm listener accumulation when cycling through Active state. Multiple listeners could accumulate if keep-alive timeouts triggered reactivation without actual channel disconnection. Listeners are now stored in FSM context and explicitly removed when transitioning away from Active state, ensuring exactly one listener is registered during each Active period.

Complete pending SessionFuture instances when session creation is aborted
via CloseSession events. The CreatingWait → Inactive and ReactivatingWait
→ Closing transitions now call handleFailureToOpenSession() to ensure any
GetSession or OpenSession futures are properly completed with
Bad_SessionClosed exceptions.

Prevent ChannelFsm listener accumulation when cycling through Active state.
Multiple listeners could accumulate if keep-alive timeouts triggered
reactivation without actual channel disconnection. Listeners are now stored
in FSM context and explicitly removed when transitioning away from Active
state, ensuring exactly one listener is registered during each Active period.
@kevinherron kevinherron added this to the 1.0.8 milestone Oct 30, 2025
Add testCloseSessionCompletesSessionFutureInReactivatingWait to verify
that pending SessionFuture instances are properly completed with an
exception when closeSession() is called during ReactivatingWait state.

This covers the ReactivatingWait → Closing transition behavior where
session futures must be completed before state transition completes.

Make State enum public to allow test access. Add javadoc to
OpcUaClient.getSessionFsm() and SessionFsm.getState().
@kevinherron kevinherron requested a review from Copilot October 31, 2025 02:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issues with SessionFuture completion and ChannelFsm listener cleanup in the OPC UA session management. The changes ensure proper exception handling when sessions are closed during wait states and fix resource leaks from transition listeners.

Key changes:

  • Added calls to handleFailureToOpenSession in CreatingWait and ReactivatingWait states to properly complete session futures with exceptions when closing
  • Improved ChannelFsm transition listener lifecycle management by storing listener references and removing them on all transitions out of Active state
  • Made the State enum public and added getState() and getSessionFsm() methods to enable external state inspection

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
State.java Changed enum visibility from package-private to public to enable external access
SessionFsm.java Added getState() method and KEY_CHANNEL_FSM_TRANSITION_LISTENER context key for listener lifecycle tracking
SessionFsmFactory.java Fixed listener cleanup, added session future completion on close in wait states, broadened transition condition
OpcUaClient.java Added getSessionFsm() method to expose SessionFsm for state inspection
SessionFsmTest.java Added test to verify SessionFuture completion when closing in ReactivatingWait state

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@ia-cmorgan ia-cmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the copyright in this file be updated?

@kevinherron kevinherron merged commit 3d4b228 into 1.0 Oct 31, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants