@@ -78,12 +78,11 @@ public async Task<TResult> ExecuteAsync<TParameters, TResult>(Command<TParameter
7878
7979 var tcs = new TaskCompletionSource < EmptyResult > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
8080
81- using var cts = cancellationToken . CanBeCanceled
82- ? CancellationTokenSource . CreateLinkedTokenSource ( cancellationToken )
83- : new CancellationTokenSource ( ) ;
81+ using CancellationTokenSource ? cts = cancellationToken . CanBeCanceled
82+ ? null
83+ : new CancellationTokenSource ( DefaultCommandTimeout ) ;
8484
85- var timeout = options ? . Timeout ?? DefaultCommandTimeout ;
86- cts . CancelAfter ( timeout ) ;
85+ var effectiveToken = cts ? . Token ?? cancellationToken ;
8786
8887 var sendBuffer = RentBuffer ( ) ;
8988
@@ -132,9 +131,9 @@ public async Task<TResult> ExecuteAsync<TParameters, TResult>(Command<TParameter
132131 var commandInfo = new CommandInfo ( tcs , descriptor . ResultTypeInfo ) ;
133132 _pendingCommands [ id ] = commandInfo ;
134133
135- using var ctsRegistration = cts . Token . Register ( ( ) =>
134+ using var ctsRegistration = effectiveToken . Register ( ( ) =>
136135 {
137- tcs . TrySetCanceled ( cts . Token ) ;
136+ tcs . TrySetCanceled ( effectiveToken ) ;
138137 _pendingCommands . TryRemove ( id , out _ ) ;
139138 } ) ;
140139
@@ -149,7 +148,7 @@ public async Task<TResult> ExecuteAsync<TParameters, TResult>(Command<TParameter
149148#endif
150149 }
151150
152- await _transport . SendAsync ( sendBuffer . WrittenMemory , cts . Token ) . ConfigureAwait ( false ) ;
151+ await _transport . SendAsync ( sendBuffer . WrittenMemory , effectiveToken ) . ConfigureAwait ( false ) ;
153152 }
154153 catch
155154 {
0 commit comments