Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

in0finite
Copy link
Contributor

@in0finite in0finite commented Oct 20, 2024

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

@in0finite in0finite changed the title better error handling in http broadcasts better error handling in http broadcasts ; remove blocking behavior from MoveNextAsync() Oct 21, 2024
@saul
Copy link
Owner

saul commented Nov 2, 2024

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.

@@ -33,50 +33,104 @@ public HttpBroadcastReader(DemoParser<TGameParser> demo, HttpClient httpClient)
_channel = Channel.CreateUnbounded<QueuedCommand>();
}

public BroadcastSyncDto? BroadcastSyncDto { get; private set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this in #122

/// <summary>
/// The most recently received tick over the HTTP broadcast.
/// </summary>
public DemoTick BufferTailTick => new(Volatile.Read(ref _tailTick));

public int EnqueuedFragmentsCount => _channel.Reader.Count;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this in #122


// Complete the Channel so that reader can be unblocked.
// Note that exception is passed to the function, so reader will fail with same exception when trying to wait on empty Channel.
_channel.Writer.Complete(ex);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this in #122

@in0finite
Copy link
Contributor Author

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.

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.

2 participants