Catch exceptions in auto discovery (#11252)
This commit is contained in:
parent
000395e036
commit
ed82d79647
|
@ -78,28 +78,36 @@ public sealed class AutoDiscoveryHost : BackgroundService
|
||||||
|
|
||||||
private async Task ListenForAutoDiscoveryMessage(IPAddress address, CancellationToken cancellationToken)
|
private async Task ListenForAutoDiscoveryMessage(IPAddress address, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using var udpClient = new UdpClient(new IPEndPoint(address, PortNumber));
|
try
|
||||||
udpClient.MulticastLoopback = false;
|
|
||||||
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
{
|
||||||
try
|
using var udpClient = new UdpClient(new IPEndPoint(address, PortNumber));
|
||||||
|
udpClient.MulticastLoopback = false;
|
||||||
|
|
||||||
|
while (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
var result = await udpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false);
|
try
|
||||||
var text = Encoding.UTF8.GetString(result.Buffer);
|
|
||||||
if (text.Contains("who is JellyfinServer?", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
{
|
||||||
await RespondToV2Message(udpClient, result.RemoteEndPoint, cancellationToken).ConfigureAwait(false);
|
var result = await udpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
var text = Encoding.UTF8.GetString(result.Buffer);
|
||||||
|
if (text.Contains("who is JellyfinServer?", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
await RespondToV2Message(udpClient, result.RemoteEndPoint, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SocketException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to receive data from socket");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SocketException ex)
|
}
|
||||||
{
|
catch (OperationCanceledException)
|
||||||
_logger.LogError(ex, "Failed to receive data from socket");
|
{
|
||||||
}
|
_logger.LogDebug("Broadcast socket operation cancelled");
|
||||||
catch (OperationCanceledException)
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
_logger.LogDebug("Broadcast socket operation cancelled");
|
{
|
||||||
}
|
// Exception in this function will prevent the background service from restarting in-process.
|
||||||
|
_logger.LogError(ex, "Unable to bind to {Address}:{Port}", address, PortNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user