From c006ff400fa5681b2dcf4cd1cd9fc13844b0800d Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Mon, 10 Jun 2024 05:50:06 -0700 Subject: [PATCH] Follow-up to #385 There is still a slim chance that the code in #385 will throw `InvalidOperationException`, since the check and call to `SetException` is not atomic. `ManualResetValueTaskSource` does not have `TrySetException` like `TaskCompletionSource`. --- RabbitMQ.Stream.Client/Client.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/RabbitMQ.Stream.Client/Client.cs b/RabbitMQ.Stream.Client/Client.cs index 80d64890..019bc979 100644 --- a/RabbitMQ.Stream.Client/Client.cs +++ b/RabbitMQ.Stream.Client/Client.cs @@ -976,11 +976,13 @@ public bool RunContinuationsAsynchronously public void SetException(Exception error) { // https://github.com/rabbitmq/rabbitmq-stream-dotnet-client/issues/384 - // we need to check if the task is pending before setting the exception - if (_logic.GetStatus(_logic.Version) == ValueTaskSourceStatus.Pending) + try { _logic.SetException(error); } + catch (InvalidOperationException) + { + } } void IValueTaskSource.GetResult(short token) => _logic.GetResult(token);