Skip to content

Reduce UnobservedTaskExceptions when instances of Connection are torn down #938

Description

@jpdillingham

The DisconnectTaskCompletionSource is created when the Connection is instantiated, but it is only ever observed when WaitForDisconnect is called (which returns the Task). When DisconnectTaskCompletionSource is finalized after the Connection is torn down, the task scheduler throws an UnobservedTaskException, which we can see in slskd if we turn on logging of these exceptions.

Think of a refactor that avoids creating this instance of TaskCompletionSource unless it's actually going to be used. Within the WaitForDisconnect method might be a good option.

There's a related issue in WaitForDisconnect as well; calling cancellationToken?.Register() creates a CancellationTokenRegistration object that is IDisposable but never gets disposed. This should be assigned to a property and disposed along with other class members.

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