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

6.5.0 can cause application freeze due to TaskScheduler change #1357

Closed
brandonagr opened this issue Jun 15, 2023 · 1 comment
Closed

6.5.0 can cause application freeze due to TaskScheduler change #1357

brandonagr opened this issue Jun 15, 2023 · 1 comment
Labels
Milestone

Comments

@brandonagr
Copy link

Describe the bug

This change #1321 replaced Task.Run with a call to Task.Factory.StartNew with some TaskCreationOptions, but it didn't specify the TaskScheduler, which actually changed the behavior from using TaskScheduler.Default to TaskScheduler.Current

https://devblogs.microsoft.com/pfxteam/task-run-vs-task-factory-startnew/

The very confusingly named TaskScheduler.Default is not the default when calling Task.Factory.StartNew, TaskScheduler.Current is the default. To preserve existing behavior the line should be updated to _mainLoopTask = Task.Factory.StartNew(MainLoop, CancellationToken.None, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);

The change in 6.5.0 caused my UI application to freeze on startup after some code to connect to rabbitmq in a background task called into rabbitmq code, the scenario is best described here in this 11 year old question predicting this issue being frequent due to the design of the task api:
https://stackoverflow.com/questions/6800705/why-is-taskscheduler-current-the-default-taskscheduler

Reproduction steps

From UI thread, use Task.Factory.StartNew(action) to run code that then initiates a rabbitmq connection. This works in 6.4 but freezes in 6.5

Expected behavior

MainLoop should always run on TaskScheduler.Default

Additional context

No response

@lukebakken
Copy link
Contributor

Fixed by #1358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants