@@ -37,9 +37,9 @@ public record ClientParameters
3737 public IDictionary < string , string > Properties { get ; } =
3838 new Dictionary < string , string >
3939 {
40- { "product" , "RabbitMQ Stream" } ,
41- { "version" , Version . VersionString } ,
42- { "platform" , ".NET" } ,
40+ { "product" , "RabbitMQ Stream" } ,
41+ { "version" , Version . VersionString } ,
42+ { "platform" , ".NET" } ,
4343 {
4444 "copyright" ,
4545 "Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term Broadcom refers to Broadcom Inc. and/or its subsidiaries."
@@ -48,7 +48,7 @@ public record ClientParameters
4848 "information" ,
4949 "Licensed under the Apache 2.0 and MPL 2.0 licenses. See https://www.rabbitmq.com/"
5050 } ,
51- { "connection_name" , "Unknown" }
51+ { "connection_name" , "Unknown" }
5252 } ;
5353
5454 public string UserName { get ; set ; } = "guest" ;
@@ -77,6 +77,8 @@ public string ClientProvidedName
7777
7878 public AuthMechanism AuthMechanism { get ; set ; } = AuthMechanism . Plain ;
7979
80+ public TimeSpan RpcTimeOut { get ; set ; } = TimeSpan . FromSeconds ( 10 ) ;
81+
8082 internal void FireMetadataUpdate ( MetaDataUpdate metaDataUpdate )
8183 {
8284 OnMetadataUpdate ? . Invoke ( metaDataUpdate ) ;
@@ -113,8 +115,6 @@ public class Client : IClient
113115 {
114116 private bool isClosed = true ;
115117
116- private readonly TimeSpan defaultTimeout = TimeSpan . FromSeconds ( 10 ) ;
117-
118118 private uint correlationId = 0 ; // allow for some pre-amble
119119
120120 private Connection _connection ;
@@ -150,7 +150,6 @@ public class Client : IClient
150150
151151 public int IncomingFrames => _connection . NumFrames ;
152152
153- //public int IncomingChannelCount => this.incoming.Reader.Count;
154153 private static readonly object Obj = new ( ) ;
155154
156155 private readonly ILogger _logger ;
@@ -494,7 +493,7 @@ private async ValueTask<TOut> Request<TIn, TOut>(Func<uint, TIn> request, TimeSp
494493 var tcs = PooledTaskSource < TOut > . Rent ( ) ;
495494 requests . TryAdd ( corr , tcs ) ;
496495 await Publish ( request ( corr ) ) . ConfigureAwait ( false ) ;
497- using var cts = new CancellationTokenSource ( timeout ?? defaultTimeout ) ;
496+ using var cts = new CancellationTokenSource ( timeout ?? Parameters . RpcTimeOut ) ;
498497 await using ( cts . Token . Register (
499498 valueTaskSource =>
500499 ( ( ManualResetValueTaskSource < TOut > ) valueTaskSource ) . SetException (
@@ -973,7 +972,16 @@ public bool RunContinuationsAsynchronously
973972 public short Version => _logic . Version ;
974973 public void Reset ( ) => _logic . Reset ( ) ;
975974 public void SetResult ( T result ) => _logic . SetResult ( result ) ;
976- public void SetException ( Exception error ) => _logic . SetException ( error ) ;
975+
976+ public void SetException ( Exception error )
977+ {
978+ // https://github.com/rabbitmq/rabbitmq-stream-dotnet-client/issues/384
979+ // we need to check if the task is pending before setting the exception
980+ if ( _logic . GetStatus ( _logic . Version ) == ValueTaskSourceStatus . Pending )
981+ {
982+ _logic . SetException ( error ) ;
983+ }
984+ }
977985
978986 void IValueTaskSource . GetResult ( short token ) => _logic . GetResult ( token ) ;
979987 T IValueTaskSource < T > . GetResult ( short token ) => _logic . GetResult ( token ) ;
0 commit comments