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

NetworkManager and others create unobserved exceptions #2642

Open
ECrownofFire opened this issue May 22, 2024 · 1 comment
Open

NetworkManager and others create unobserved exceptions #2642

ECrownofFire opened this issue May 22, 2024 · 1 comment

Comments

@ECrownofFire
Copy link

This is mostly relevant when using logging solutions such as Sentry that hook into TaskScheduler.UnobservedTaskException. Unobserved tasks can be a major source of bugs, so I'd really like to keep noisiness in that event to a minimum.

On this line in NetworkManager, an exception is set on a Task that can only be observed if that response's body is attempted to be read.

There are a few other places where unobserved exceptions are created as well, such as here in IsolatedWorld.

Exceptions can be forcefully marked as observed with a snippet such as this, placed before TrySetException.

TaskCompletionSource taskWrapper;
// [...]

// Ensure that the exception is always marked as observed
taskWrapper.Task.ContinueWith(
    (t) => { _ = t.Exception; },
    CancellationToken.None,
    TaskContinuationOptions.OnlyOnFaulted,
    TaskScheduler.Default);
taskWrapper.TrySetException(new Exception("Something went wrong"));

It's not really ideal, but something like this should probably be placed everywhere that an exception is set that doesn't need to be observed. Several of these are basically just asynchronous getters that only want to throw an error when the result is unavailable, so observing them is unnecessary if they're not called.

@kblok
Copy link
Member

kblok commented May 22, 2024

I had many attempts to resolve this here and here but I found no solutions.

PRs are welcome.

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

No branches or pull requests

2 participants