Fix unsubscribe + reduce bot update db query

This commit is contained in:
2025-09-15 00:42:24 +07:00
parent b0d2dcc6b9
commit d2dbee9a5f
3 changed files with 27 additions and 5 deletions

View File

@@ -67,11 +67,25 @@ public class CandleStoreGrain : Grain, ICandleStoreGrain, IAsyncObserver<Candle>
public override async Task OnDeactivateAsync(DeactivationReason reason, CancellationToken cancellationToken)
{
// Unsubscribe from the stream
// Unsubscribe from the stream with proper error handling
if (_streamSubscription != null)
{
await _streamSubscription.UnsubscribeAsync();
_streamSubscription = null;
try
{
await _streamSubscription.UnsubscribeAsync();
_logger.LogDebug("Successfully unsubscribed from stream for grain {GrainKey}", this.GetPrimaryKeyString());
}
catch (Exception ex)
{
// Log the error but don't throw - this is common during shutdown when
// the pub-sub rendezvous grain may already be deactivated
_logger.LogWarning(ex, "Failed to unsubscribe from stream during deactivation for grain {GrainKey}. This is normal during shutdown.",
this.GetPrimaryKeyString());
}
finally
{
_streamSubscription = null;
}
}
await base.OnDeactivateAsync(reason, cancellationToken);