From 7dc2071d80879d8f29ba5f69df0fdb95da668cc4 Mon Sep 17 00:00:00 2001 From: "Sahin Kemal (BT-CO ENG5.1)" Date: Mon, 16 Feb 2026 14:42:48 +0100 Subject: [PATCH] Fix discover exception due to race condition when the timeout occures, finally block disposes the UDP client while pending ReceiveAsync operation. This leads to race condition where socket is disposed while the receive operation is still trying to complete, resulting in ObjectDisposedException. --- Discovery/WSDiscovery.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Discovery/WSDiscovery.cs b/Discovery/WSDiscovery.cs index d1ea346..567ea8a 100644 --- a/Discovery/WSDiscovery.cs +++ b/Discovery/WSDiscovery.cs @@ -65,6 +65,14 @@ public async Task> Discover(int Timeout, IUdpClient { isRunning = false; } + catch (ObjectDisposedException) + { + isRunning = false; + } + catch (SocketException) + { + isRunning = false; + } finally { client.Close();