Coder Social home page Coder Social logo

crash during discovery about onvif-discovery HOT 3 CLOSED

vicmaeg avatar vicmaeg commented on May 20, 2024
crash during discovery

from onvif-discovery.

Comments (3)

ispysoftware avatar ispysoftware commented on May 20, 2024

... needed to add

catch(Exception ex) {
// Other exception
}

to line 91 of Discovery.cs

from onvif-discovery.

vicmaeg avatar vicmaeg commented on May 20, 2024

Hello @ispysoftware, Thanks for reporting the issue. Can I know in which OS and target runtime is running the .netstandard library? I could not reproduce it. Did you reproduce it constantly? or some of the times? just to know if some sort of a race condition between the udpClient.Close() and udpClient.ReceiveAsync(). Also I need the Exception Type is it a ObjectDisposedException or SocketException

You need to add the following to make it working?

} finally {
  try {
    client.Close ();
  } catch {
    // socket close failed
  }
}

or the following?

} catch (OperationCanceledException) {
// Either the user canceled the action or the timeout has fired
} catch (Exception) {
// ReceiveAsync failed
} finally {
  client.Close ();
}

But yeah this can happen because UdpClient.ReceiveAsync does not have a CancellationToken, so what I do is the following:

                /// <summary>
		/// Used to provide cancellation possibility to any Async Methods returning a Task
		/// </summary>
		internal static async Task<T> WithCancellation<T> (this Task<T> task, CancellationToken cancellationToken)
		{
			var tcs = new TaskCompletionSource<bool> ();
			using (cancellationToken.Register (s => ((TaskCompletionSource<bool>)s).TrySetResult (true), tcs)) {
				if (task != await Task.WhenAny (task, tcs.Task)) {
					throw new OperationCanceledException (cancellationToken);
				}
			}
			return await task;
		}

This just returns when the initial task (ReceiveAsync) finishes or the cancellationToken is cancelled, but in fact the ReceiveAsync is still executing...

I will investigate if there is a better solution to manage the cancellation of the opened Udp socket.

from onvif-discovery.

ispysoftware avatar ispysoftware commented on May 20, 2024

it was working for ages but then one of my cameras started malfunctioning and closing the request which triggered the exception in the library so reproducing it is hard unless you build a virtual client that just closes the response. Until I rebooted the camera it was happening on every run of the discovery code.

Running on Windows 10, .Net Framework 4.7

adding the catch-all case after OperationCanceledException "fixed" it.

from onvif-discovery.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.