@@ -196,7 +196,7 @@ public override string ToString()
196196
197197 internal Task CloseFrameHandlerAsync ( )
198198 {
199- return InnerConnection . FrameHandler . CloseAsync ( ) ;
199+ return InnerConnection . FrameHandler . CloseAsync ( CancellationToken . None ) ;
200200 }
201201
202202 ///<summary>API-side invocation of updating the secret.</summary>
@@ -208,17 +208,44 @@ public Task UpdateSecretAsync(string newSecret, string reason)
208208 }
209209
210210 ///<summary>Asynchronous API-side invocation of connection.close with timeout.</summary>
211- public async Task CloseAsync ( ushort reasonCode , string reasonText , TimeSpan timeout , bool abort , CancellationToken cancellationToken = default )
211+ public async Task CloseAsync ( ushort reasonCode , string reasonText , TimeSpan timeout , bool abort ,
212+ CancellationToken cancellationToken = default )
212213 {
213214 ThrowIfDisposed ( ) ;
214- // TODO
215- // what to do if this method throws OperationCanceledException? We still need to close the connection.
216- await StopRecoveryLoopAsync ( cancellationToken )
217- . ConfigureAwait ( false ) ;
218- if ( _innerConnection . IsOpen )
215+
216+ Task CloseInnerConnectionAsync ( )
217+ {
218+ if ( _innerConnection . IsOpen )
219+ {
220+ return _innerConnection . CloseAsync ( reasonCode , reasonText , timeout , abort , cancellationToken ) ;
221+ }
222+ else
223+ {
224+ return Task . CompletedTask ;
225+ }
226+ }
227+
228+ try
219229 {
220- await _innerConnection . CloseAsync ( reasonCode , reasonText , timeout , abort , cancellationToken )
230+ await StopRecoveryLoopAsync ( cancellationToken )
221231 . ConfigureAwait ( false ) ;
232+
233+ await CloseInnerConnectionAsync ( )
234+ . ConfigureAwait ( false ) ;
235+ }
236+ catch ( Exception ex )
237+ {
238+ try
239+ {
240+ await CloseInnerConnectionAsync ( )
241+ . ConfigureAwait ( false ) ;
242+ }
243+ catch ( Exception innerConnectionException )
244+ {
245+ throw new AggregateException ( ex , innerConnectionException ) ;
246+ }
247+
248+ throw ;
222249 }
223250 }
224251
0 commit comments