Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/NATS.Client.Core/NatsSubBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ public virtual ValueTask DisposeAsync()
_idleTimeoutTimer?.Dispose();
_startUpTimeoutTimer?.Dispose();

_tokenRegistration.Dispose();

if (Exception != null)
{
if (Exception is NatsSubException { Exception: not null } nse)
Expand All @@ -249,8 +251,6 @@ public virtual ValueTask DisposeAsync()
throw Exception;
}

_tokenRegistration.Dispose();

return unsubscribeAsync;
}

Expand Down
20 changes: 13 additions & 7 deletions src/NATS.Client.JetStream/Internal/NatsJSConsume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,22 @@ public void Delivered(int msgSize)
public override async ValueTask DisposeAsync()
{
Interlocked.Exchange(ref _disposed, 1);
await base.DisposeAsync().ConfigureAwait(false);
await _pullTask.ConfigureAwait(false);
try
{
await base.DisposeAsync().ConfigureAwait(false);
}
finally
{
await _pullTask.ConfigureAwait(false);
#if NETSTANDARD2_0
_timer.Dispose();
_timer.Dispose();
#else
await _timer.DisposeAsync().ConfigureAwait(false);
await _timer.DisposeAsync().ConfigureAwait(false);
#endif
if (_notificationChannel != null)
{
await _notificationChannel.DisposeAsync();
if (_notificationChannel != null)
{
await _notificationChannel.DisposeAsync();
}
}
}

Expand Down
22 changes: 14 additions & 8 deletions src/NATS.Client.JetStream/Internal/NatsJSFetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,23 @@ public void ResetHeartbeatTimer()
public override async ValueTask DisposeAsync()
{
Interlocked.Exchange(ref _disposed, 1);
await base.DisposeAsync().ConfigureAwait(false);
try
{
await base.DisposeAsync().ConfigureAwait(false);
}
finally
{
#if NETSTANDARD2_0
_hbTimer.Dispose();
_expiresTimer.Dispose();
_hbTimer.Dispose();
_expiresTimer.Dispose();
#else
await _hbTimer.DisposeAsync().ConfigureAwait(false);
await _expiresTimer.DisposeAsync().ConfigureAwait(false);
await _hbTimer.DisposeAsync().ConfigureAwait(false);
await _expiresTimer.DisposeAsync().ConfigureAwait(false);
#endif
if (_notificationChannel != null)
{
await _notificationChannel.DisposeAsync();
if (_notificationChannel != null)
{
await _notificationChannel.DisposeAsync();
}
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/NATS.Client.JetStream/Internal/NatsJSOrderedConsume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,19 @@ public override async ValueTask DisposeAsync()
Interlocked.Exchange(ref _disposed, 1);

_context.Connection.ConnectionDisconnected -= ConnectionOnConnectionDisconnected;

await base.DisposeAsync().ConfigureAwait(false);
await _pullTask.ConfigureAwait(false);
try
{
await base.DisposeAsync().ConfigureAwait(false);
}
finally
{
await _pullTask.ConfigureAwait(false);
#if NETSTANDARD2_0
_timer.Dispose();
_timer.Dispose();
#else
await _timer.DisposeAsync().ConfigureAwait(false);
await _timer.DisposeAsync().ConfigureAwait(false);
#endif
}
}

internal override ValueTask WriteReconnectCommandsAsync(CommandWriter commandWriter, int sid)
Expand Down