Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions src/Orleans.Runtime/Catalog/ActivationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -843,14 +843,25 @@ public async ValueTask DisposeAsync()
{
}

switch (_serviceScope)
await DisposeAsync(_serviceScope);
}

private static async ValueTask DisposeAsync(object obj)
{
try
{
case IAsyncDisposable asyncDisposable:
if (obj is IAsyncDisposable asyncDisposable)
{
await asyncDisposable.DisposeAsync();
break;
case IDisposable disposable:
}
else if (obj is IDisposable disposable)
{
disposable.Dispose();
break;
}
}
catch
{
// Ignore.
}
}

Expand Down Expand Up @@ -1202,7 +1213,7 @@ async Task ProcessOperationsAsync()
}
finally
{
(op as IDisposable)?.Dispose();
await DisposeAsync(op);
}
}
}
Expand Down Expand Up @@ -1255,10 +1266,6 @@ private void RehydrateInternal(IRehydrationContext context)
{
_shared.Logger.LogError(exception, "Error while rehydrating activation");
}
finally
{
(context as IDisposable)?.Dispose();
}
}

private void OnDehydrate(IDehydrationContext context)
Expand Down Expand Up @@ -2023,7 +2030,7 @@ private sealed class DeactivationInfo
}
}

private abstract class Command(CancellationTokenSource cts)
private abstract class Command(CancellationTokenSource cts) : IDisposable
{
private bool _disposed;
private readonly CancellationTokenSource _cts = cts;
Expand All @@ -2040,26 +2047,41 @@ public virtual void Cancel()

public virtual void Dispose()
{
lock (this)
try
{
_disposed = true;
_cts.Dispose();
lock (this)
{
_disposed = true;
_cts.Dispose();
}
}
catch
{
// Ignore.
}

GC.SuppressFinalize(this);
}

public sealed class Deactivate(CancellationTokenSource cts, ActivationState previousState) : Command(cts)
{
public ActivationState PreviousState { get; } = previousState;
}

public sealed class Activate(Dictionary<string, object>? requestContext, CancellationTokenSource cts) : Command(cts), IDisposable
public sealed class Activate(Dictionary<string, object>? requestContext, CancellationTokenSource cts) : Command(cts)
{
public Dictionary<string, object>? RequestContext { get; } = requestContext;
}

public sealed class Rehydrate(IRehydrationContext context) : Command(new())
{
public readonly IRehydrationContext Context = context;

public override void Dispose()
{
base.Dispose();
(Context as IDisposable)?.Dispose();
}
}

public sealed class Delay(TimeSpan duration) : Command(new())
Expand Down