Skip to content

Add a way to give a name or description to waits so that callers don't get an opaque "The wait timed out after 5000 milliseconds" #960

Description

@jpdillingham

I'm debugging something with the DownloadAsync method at the moment, and I'm causing one of the internal waits to throw by manipulating a remote client. This is "working" for the time being, but the exception that's thrown when a wait expires is extremely opaque; I'm not sure which of the several internal waits elapsed.

Here's the current signature of the void Wait:

Task Wait(WaitKey key, int? timeout = null, CancellationToken? cancellationToken = null);

This could be updated like so:

Task Wait(WaitKey key, string name = null, int? timeout = null, CancellationToken? cancellationToken = null);

The provided name could be stored inside of the PendingWait class, and then the Timeout implementation could be updated like:

        public void Timeout(WaitKey key)
        {
            Disposition(key, wait =>
                wait.TaskCompletionSource.TrySetException(new TimeoutException($"The wait{(string.IsNullOrEmpty(wait.Name) ? " " : $" for {wait.Name}")} timed out after {wait.Timeout} milliseconds")));
        }

The only downside is the string allocation and storage in PendingWait, so some analysis will need to be done regarding the typical number of pending waits during different operations (potentially tens of thousands during a heavy search) and the Waiter class probably needs to be pulled out and have the heap inspected with growing numbers of instances.

I'm not sure I'll do it, the risk:reward ratio isn't the greatest.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions