Skip to content

Commit

Permalink
fix(MulticastClient): ignore receive error. Fixes #79
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Oct 5, 2019
1 parent 597bc97 commit 94e3416
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/MulticastClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ await sender.Value.SendAsync(

void Listen(UdpClient receiver)
{
// ReceiveAsync does not support cancellation. So the receiver is disposed
// to stop it. See https://github.com/dotnet/corefx/issues/9848
Task.Run(async () =>
{
try
Expand All @@ -173,6 +175,10 @@ void Listen(UdpClient receiver)

await task.ConfigureAwait(false);
}
catch (NullReferenceException)
{
return;
}
catch (ObjectDisposedException)
{
return;
Expand Down Expand Up @@ -204,15 +210,29 @@ protected virtual void Dispose(bool disposing)

foreach (var receiver in receivers)
{
receiver.Dispose();
try
{
receiver.Dispose();
}
catch
{
// eat it.
}
}
receivers.Clear();

foreach (var address in senders.Keys)
{
if (senders.TryRemove(address, out var sender))
{
sender.Dispose();
try
{
sender.Dispose();
}
catch
{
// eat it.
}
}
}
senders.Clear();
Expand Down

0 comments on commit 94e3416

Please sign in to comment.