Skip to content

Commit

Permalink
Merge pull request #107 from xcomponent/FixDispose
Browse files Browse the repository at this point in the history
Prevent Dispose from throwing Exceptions
  • Loading branch information
Julien-Molina committed Jun 19, 2019
2 parents 6b5c4f0 + 71c3c0c commit 0f3f1a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions ReactiveXComponent/RabbitMq/RabbitMqSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,19 @@ private void Dispose(bool disposing)
// clear managed resources
foreach (var subscriberInfo in _subscribersDico.Values)
{
if (subscriberInfo.Channel.IsOpen)
try
{
subscriberInfo.Channel.ModelShutdown -= ChannelOnModelShutdown;
subscriberInfo.Channel.BasicCancel(subscriberInfo.Subscriber.ConsumerTag);
if (subscriberInfo.Channel.IsOpen)
{
subscriberInfo.Channel.BasicCancel(subscriberInfo.Subscriber.ConsumerTag);
}
}

catch (Exception)
{
// Don't throw exception in Dispose
}

subscriberInfo.Channel.Dispose();

foreach (var handler in subscriberInfo.Handlers)
Expand Down
4 changes: 2 additions & 2 deletions ReactiveXComponent/WebSocket/WebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private void Dispose(bool disposing)
_webSocket.Error -= WebSocketOnError;
_webSocket.MessageReceived -= WebSocketOnMessageReceived;

_socketOpenEvent.Dispose();
_socketCloseEvent.Dispose();
_socketOpenEvent?.Dispose();
_socketCloseEvent?.Dispose();
}

// clear unmanaged resources
Expand Down

0 comments on commit 0f3f1a5

Please sign in to comment.