saul / demofile-net

Blazing fast cross-platform demo parser library for Counter-Strike 2 and Valve's Deadlock, written in C#.
MIT License
111 stars 10 forks source link

better error handling in http broadcasts ; remove blocking behavior from `MoveNextAsync()` #119

Open in0finite opened 1 month ago

in0finite commented 1 month ago

This will prevent blocking in MoveNextAsync(), by calling Writer.Complete() when exception happens, and will throw appropriate exception (the one from worker) when Channel becomes empty.

So instead of blocking application for 10-15 seconds (like you suggested in other issue) when http broadcast has ended, you get the right exception immediately.

This PR also stops worker from entering infinite loop, when server starts returning 404 error for finished match.

Edit: removed blocking behavior from MoveNextAsync(), and added another method WaitForAvailableDataAsync() with same functionality

saul commented 2 weeks ago

Thanks for raising these issues - rather than adding more retry/throttling logic into this library, I've added an example of how to do this in the HttpClient: https://github.com/saul/demofile-net/pull/122/files. I will most likely move forward with this approach rather than the implementation you did here - I believe you can achieve the same behaviour this way still.

in0finite commented 2 weeks ago

That PR still doesn't solve the issue of blocking : MoveNextAsync() can still block even if EnqueuedFragmentsCount > 0, because it waits multiple times in a loop, so it can process multiple fragments without advancing tick, and block.