Skip to content

Commit

Permalink
RavenDB-21028 : Operation.WaitForCompletion : don't await the additio…
Browse files Browse the repository at this point in the history
…nal task if we had an error during processing, since it can cause us to hang
  • Loading branch information
aviv86 committed Aug 9, 2023
1 parent 9e23c73 commit 50680bd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Raven.Client/Documents/Operations/Operation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Operation : IObserver<OperationStatusChange>
private readonly RequestExecutor _requestExecutor;
private readonly Func<IDatabaseChanges> _changes;
private readonly DocumentConventions _conventions;
private readonly Task _additionalTask;
private Task _additionalTask;
private readonly long _id;
private TaskCompletionSource<IOperationResult> _result = new TaskCompletionSource<IOperationResult>(TaskCreationOptions.RunContinuationsAsynchronously);
private readonly SemaphoreSlim _lock = new SemaphoreSlim(1, 1);
Expand Down Expand Up @@ -355,6 +355,7 @@ public async Task<TResult> WaitForCompletionAsync<TResult>(CancellationToken tok
catch (Exception e)
{
await StopProcessingUnderLock(e).ConfigureAwait(false);
_additionalTask = Task.CompletedTask; // don't await the additional task if we had an error
}

await _additionalTask.ConfigureAwait(false);
Expand Down
33 changes: 33 additions & 0 deletions test/SlowTests/Issues/RavenDB-21028.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Threading.Tasks;
using Xunit.Abstractions;
using System;
using FastTests;
using Raven.Client.Documents.Smuggler;
using Raven.Client.Exceptions;
using Tests.Infrastructure;
using Xunit;

namespace SlowTests.Issues
{
public class RavenDB_21028 : RavenTestBase
{

public RavenDB_21028(ITestOutputHelper output) : base(output)
{
}

[RavenFact(RavenTestCategory.Smuggler)]
public async Task WaitForCompletionShouldNotHangOnFailureDuringExport()
{
using var store = GetDocumentStore();
await store.Maintenance.SendAsync(new CreateSampleDataOperation());

var file = GetTempFileName();
var op = await store.Smuggler.ExportAsync(new DatabaseSmugglerExportOptions { EncryptionKey = "fakeKey" }, file);

await Assert.ThrowsAsync<RavenException>(async () => await op.WaitForCompletionAsync(TimeSpan.FromSeconds(10)));

}

}
}

0 comments on commit 50680bd

Please sign in to comment.