sportradar / UnifiedOddsSdkNetCore

UnifiedFeed SDK is a client library that enables easier integration with the Betradar XML feeds. SDK exposes XML feed service interface in a more user-friendly way and isolates the client from having to do XML feed parsing, proper connection handling, error recovery, event queuing, data caching and dispatching.
https://sportradar.github.io/UnifiedOddsSdkNetCore/
Other
17 stars 14 forks source link

Unhandled exception on SdkTimer.OnTick cause application to crash #19

Closed micdenny closed 1 year ago

micdenny commented 1 year ago

Description

This method can produce an Unhandled Exception that then can cause a crash of the application that uses the SDK.

https://github.com/sportradar/UnifiedOddsSdkNetCore/blob/3885a1147faa8349a90a375896da3d249795928b/src/Sportradar.OddsFeed.SDK/Common/Internal/SdkTimer.cs#L68-L72

This is an exception took from a real environment:

CoreCLR Version: 4.700.21.51404
.NET Core Version: 3.1.21
Description: The application requested process termination through System.Environment.FailFast(string message).
Message:    at Sportradar.OddsFeed.SDK.API.Internal.ProducerRecoveryManager.CheckStatus()
   at Sportradar.OddsFeed.SDK.API.Internal.FeedRecoveryManager.OnTimerElapsed(Object source, EventArgs e)
   at Sportradar.OddsFeed.SDK.Common.Internal.SdkTimer.OnTick(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.TimerQueueTimer.CallCallback(Boolean isThreadPool)
   at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
   at System.Threading.TimerQueue.FireNextTimers()

Description: The process was terminated due to an unhandled exception.System.Diagnostics.DebugProvider+DebugAssertException:    at Sportradar.OddsFeed.SDK.API.Internal.ProducerRecoveryManager.CheckStatus()
   at Sportradar.OddsFeed.SDK.API.Internal.FeedRecoveryManager.OnTimerElapsed(Object source, EventArgs e)
   at Sportradar.OddsFeed.SDK.Common.Internal.SdkTimer.OnTick(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.TimerQueueTimer.CallCallback(Boolean isThreadPool)
   at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
   at System.Threading.TimerQueue.FireNextTimers()

Stack:
   at System.Environment.FailFast(System.String, System.Exception, System.String)
   at System.Diagnostics.DebugProvider.FailCore(System.String, System.String, System.String, System.String)
   at System.Diagnostics.DefaultTraceListener.Fail(System.String, System.String)
   at System.Diagnostics.TraceInternal.Fail(System.String, System.String)
   at System.Diagnostics.TraceInternal+TraceProvider.Fail(System.String, System.String)
   at Sportradar.OddsFeed.SDK.API.Internal.ProducerRecoveryManager.CheckStatus()
   at Sportradar.OddsFeed.SDK.API.Internal.FeedRecoveryManager.OnTimerElapsed(System.Object, System.EventArgs)
   at Sportradar.OddsFeed.SDK.Common.Internal.SdkTimer.OnTick(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.TimerQueueTimer.CallCallback(Boolean)
   at System.Threading.TimerQueueTimer.Fire(Boolean)
   at System.Threading.TimerQueue.FireNextTimers()

Resolution

Wrap the OnTick method body in a try-catch clause and log the error without throwing it again.

If SdkTimer is just a pure implementation of a Timer and you don't want to catch the exception there, then you have to look every usages and check that the callback is catching the exception and logging it, like in this method:

https://github.com/sportradar/UnifiedOddsSdkNetCore/blob/3885a1147faa8349a90a375896da3d249795928b/src/Sportradar.OddsFeed.SDK/API/Internal/FeedRecoveryManager.cs#L134-L157

micdenny commented 1 year ago

Then another point of the exception took my attention, when I saw DebugProvider in it, does the DLL be compiled in DEBUG mode? why this?


I've opened a separated issue about this #20

dhrovat commented 1 year ago

Thank you for pointing that out. Implemented try-catch around that as suggested. Will be available in next release.

dhrovat commented 1 year ago

This was fixed and is available since v1.29.1. Also latest versions are published in Release mode.