Skip to content

TaskScheduler.Current should not be used to start OperationQueue #406

@grokys

Description

@grokys

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

OperationQueue uses the Task constructor followed by task.Start() to start a long-running processing task.

This is sometimes causing a hang in GitHub for Visual Studio because task.Start() uses TaskScheduler.Current, which in the problematic case is an instance of VsUINormalPriorityScheduler, which seems to run tasks on the UI thread.

In addition, the Task ctor just takes an Action and not a Task<Func> means that the returned task will be signaled as completed as soon as it awaits, and the ``task.Wait()` in the returned disposable won't actually be waiting for the task to complete.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

It's not easy to demo, as it happens inside VS and only intermittently at that, However, I've spoken with @paulcbetts on slack and he's confirmed that this looks like a bug.

I'll submit a PR shortly with a fix.

What is the expected behavior?

When starting the task, need to make sure that a threadpool scheduler is used, rather than TaskScheduler.Default (which can be anything).

What is the motivation / use case for changing the behavior?

Not hanging Visual Studio ;)

Which versions of Akavache, and which platform / OS are affected by this issue? Did this work in previous versions of Akavache? Please also test with the latest stable and snapshot (https://www.myget.org/feed/Akavache/package/nuget/Akavache) versions.

Afaics this issue is present in all versions.

Other information (e.g. stacktraces, related issues, suggestions how to fix)

Stacktraces etc can be found at: github/VisualStudio#1662

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions