fix: trigger onOpen callback in Swift WebSocket after upgrade completes #1233
      
        
          +7
        
        
          −1
        
        
          
        
      
    
  
  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.
  
    
  
    
Problem
The
onOpencallback was not being triggered when a WebSocket connection was established in the Swift WebSocket client. This affected all SDKs that depend on this implementation, including the Apple (iOS/macOS) SDK.Root Cause
The issue was caused by a lifecycle timing problem in the NIO channel handler pipeline:
channelActiveevent fires for existing handlersMessageHandleradded to the pipelinechannelActivemethod never gets calledThe
channelActivecallback only fires when a handler is added to a channel that is not yet active. By the time ourMessageHandleris added, the channel is already active from the HTTP connection phase.Solution
The fix explicitly triggers the
onOpencallback in theupgradePipelineHandlermethod after successfully adding theMessageHandlerto the pipeline:This ensures the callback is invoked at the correct time - when the WebSocket connection is fully established and ready to send/receive messages.
Impact
This fix ensures that:
onOpencallbacks work correctly in the Swift WebSocket clientonOpencallback now functions as expectedTesting
Tested with Apple SDK Realtime service which uses this WebSocket client as a dependency.
Summary by CodeRabbit