ais-dotnet / Ais.Net.Receiver

A simple .NET AIS Receiver for capturing the Norwegian Coastal Administration AIS network data (available under Norwegian license for public data (NLOD)) and persisting in Microsoft Azure Blob Storage. Sponsored by endjin.
Apache License 2.0
19 stars 12 forks source link

Handle parse errors in ReceiverHost #141

Closed idg10 closed 2 years ago

idg10 commented 2 years ago

Bad AIS messages are a fact of life. The NmeaLineParser constructor detects various clear indications of bad data and throws an ArgumentException. The ReceiverHost does not handle these exceptions, causing it to crash if a bad message is received.

We should handle ArgumentException from this line:

https://github.com/ais-dotnet/Ais.Net.Receiver/blob/88f5211c37c6a3156d4d79ff2f47bdb77b1455b6/Solutions/Ais.Net.Receiver/Ais/Net/Receiver/Receiver/ReceiverHost.cs#L59

We should consider adding a new IObservable<T> property reporting these bad lines, so that applications can still do something with them. (E.g., if we're recording all incoming messages, it may be useful to include incomplete/corrupt ones, because manual inspection might be able to infer something from the data.)

joshdadswellijyi commented 2 years ago

I also came accross this isse with the ReceiverHost and also spotted that the Retry mechanism that these exceptions are falling back on does not seem to be functioning correctly. It recreates the NmeaToAisMessageTypeProcessor and the NmeaLineToAisStreamAdapter but without recreating the TcpClient in NetworkStreamNmeaReceiver I was unable to re-attatch to the stream as the TcpClient had already been disposed of.

https://github.com/ais-dotnet/Ais.Net.Receiver/blob/b26efc75344bb7d0dd9f09483227c721cae4189e/Solutions/Ais.Net.Receiver/Ais/Net/Receiver/Receiver/ReceiverHost.cs#L39-L44

I completely agree with your change as it will eliminate the need for the Retryable to fire in these situations but it may also be worth having a look at that mechanism as it may not be functioning as intended.

joshdadswellijyi commented 2 years ago

142 Raised a PR

idg10 commented 2 years ago

Added in #142