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

Debugger locks up the app when there are many threads/web requests #7938

Open
mattleibow opened this issue Jan 22, 2025 · 4 comments
Open

Debugger locks up the app when there are many threads/web requests #7938

mattleibow opened this issue Jan 22, 2025 · 4 comments
Labels

Comments

@mattleibow
Copy link
Member

mattleibow commented Jan 22, 2025

Type: Bug

Not sure who or what is to blame here, but something is causing my app to freeze and the debugger seems to just block on exceptions.

If you run this app with the debugger on Mac Catalyst it will freeze when scrolling quickly. But, if you launch without the debugger, it works fine. Also, if you scroll slow enough so that only 1 or 2 images scroll on screen at a time, then the images load - even with the debugger.

Swapping to labels also work fine.

Images in maui are downloaded using HttpClient, so something is happening when the app starts requesting many images and then cancelling them. I will try reproduce without UI controls as soon as I can.

Extension version: 2.62.18
VS Code version: Code - Insiders 1.97.0-insider (Universal) (d226a2a497b928d78aa654f74c8af5317d3becfb, 2025-01-22T05:05:14.565Z)
OS version: Darwin arm64 23.6.0
Modes:

System Info
Item Value
CPUs Apple M1 Pro (8 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 53, 49, 44
Memory (System) 32.00GB (0.25GB free)
Process Argv --crash-reporter-id 6698d004-6faf-44a5-a725-f730c3f1de63
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
vsaa593cf:30376535
py29gd2263:31024238
c4g48928:30535728
962ge761:30841072
9b8hh234:30694863
pythonnoceb:30776497
dsvsc014:30777825
dsvsc015:30821418
pythonmypyd1:30859725
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:30980852
pythonait:30973460
dvdeprecation:31040973
dwnewjupytercf:31046870
2f103344:31071589
nativerepl1:31134653
pythonrstrctxt:31093868
nativeloc1:31118317
cf971741:31144450
e80f6927:31120813
iacca1:31150324
notype1:31143044
dwcopilot:31158714
h409b430:31177054
c3hdf307:31184662
6074i472:31201624
dwoutputs:31217127
8did9651:31218798
9064b325:31222308
copilot_t_ci:31222730

@mattleibow
Copy link
Member Author

Source code for the lazy (after dotnet new maui):

<CollectionView x:Name="cv">
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <Grid Padding="6">
                <Image
                    Source="{Binding Image}"
                    Aspect="AspectFill"
                    HeightRequest="100"
                    WidthRequest="100"/>
            </Grid>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>
public partial class MainPage : ContentPage
{
	public MainPage()
	{
		InitializeComponent();

		var items = new List<Item>();

		for (var i = 0; i < 1085; i++)
		{
			items.Add(new Item
			{
				Image = $"https://picsum.photos/100/100?image={i}"
			});
		}

		cv.ItemsSource = items;
	}

	class Item
	{
		public string? Image { get; set; }
	}
}

@mattleibow
Copy link
Member Author

Added a mac catalyst sample that also freezes.

@mattleibow
Copy link
Member Author

mattleibow commented Jan 23, 2025

I could simplify this in mac catalyst a bit more:

public async void DoWork()
{
	await Task.Delay(1000);

	Debug.WriteLine("Hello, World!");

	for (int i = 0; i < 1100; i++)
	{
		var cancel = (i % 100) != 0;

		Debug.WriteLine($"Starting {i} => cancel: {cancel}");

		_ = NewMethod(i, cancel);

		await Task.Delay(100);
	}

	Debug.WriteLine("Done");
}

static async Task NewMethod(int item, bool cancel)
{
	try
	{
		var cts = new CancellationTokenSource();

		if (cancel)
			cts.CancelAfter(250);

		await Task.Run(async () => {
			await Task.Delay(1000, cts.Token);
		}, cts.Token);

		Console.WriteLine($"{item} => done");
	}
	catch (Exception ex)
	{
		Debug.WriteLine($"{item} => {ex.Message}");
	}
}

@gregg-miskelly
Copy link
Contributor

A few questions:

  1. By "freeze" do you mean that it will pause for a while (say a second or two)? Or that it will hang and never recover?
  2. What version of .NET are you targeting?
  3. Do you have Just My Code enabled? (it is on by default)
  4. If it is hanging completely, what happens if you hit the pause key?
  5. If you look in the debug console, you should see a line for all the cancellation exceptions the code you included has. How many do you see?

The performance of .NET Exceptions under the debugger is several orders of magnitude worse than when a debugger is attached when it is not, especially if Just My Code isn't enabled. So, I am guessing that is what you are experiencing. But we will see.

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