Skip to content

Fix discover exception due to race condition#61

Open
sak1ein-keen wants to merge 1 commit intoJazea:masterfrom
sak1ein-keen:kemal-fix-discover-exception-due-to-race-condition
Open

Fix discover exception due to race condition#61
sak1ein-keen wants to merge 1 commit intoJazea:masterfrom
sak1ein-keen:kemal-fix-discover-exception-due-to-race-condition

Conversation

@sak1ein-keen
Copy link
Copy Markdown

@sak1ein-keen sak1ein-keen commented Feb 16, 2026

When the timeout occurs, 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.

`

An exception occured: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'
at System.Net.Sockets.UdpClient.EndReceiveFrom(IAsyncResult asyncResult, IPEndPoint& endPoint)
at System.Net.Sockets.UdpClient.EndReceive(IAsyncResult asyncResult, IPEndPoint& remoteEP)
at System.Net.Sockets.UdpClient.b__64_1(IAsyncResult ar)
at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServiers.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Onvif.Core.Discovery.Common.UdpClientWrapper.d__11.MoveNext()

`

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant